@@ -26,20 +26,20 @@ function TranscodingStreams.process(
26
26
codec :: DoubleFrameEncoder ,
27
27
input :: TranscodingStreams.Memory ,
28
28
output :: TranscodingStreams.Memory ,
29
- error :: TranscodingStreams.Error ,
29
+ error_ref :: TranscodingStreams.Error ,
30
30
)
31
31
if input. size == 0
32
32
codec. got_stop_msg[] = true
33
33
end
34
34
35
35
if output. size < 2
36
- error [] = ErrorException (" requires a minimum of 2 bytes of output space" )
36
+ error_ref [] = ErrorException (" requires a minimum of 2 bytes of output space" )
37
37
return 0 , 0 , :error
38
38
elseif codec. stopped[]
39
- error [] = ErrorException (" cannot process after stopped" )
39
+ error_ref [] = ErrorException (" cannot process after stopped" )
40
40
return 0 , 0 , :error
41
41
elseif codec. got_stop_msg[] && input. size != 0
42
- error [] = ErrorException (" cannot accept more input after getting stop message" )
42
+ error_ref [] = ErrorException (" cannot accept more input after getting stop message" )
43
43
return 0 , 0 , :error
44
44
elseif ! codec. opened[]
45
45
output[1 ] = UInt8 (' [' )
@@ -95,7 +95,7 @@ function TranscodingStreams.process(
95
95
codec :: DoubleFrameDecoder ,
96
96
input :: TranscodingStreams.Memory ,
97
97
output :: TranscodingStreams.Memory ,
98
- error :: TranscodingStreams.Error ,
98
+ error_ref :: TranscodingStreams.Error ,
99
99
)
100
100
Δin:: Int = 0
101
101
Δout:: Int = 0
@@ -167,7 +167,7 @@ function TranscodingStreams.process(
167
167
catch e
168
168
codec. state[]= 7
169
169
e isa ErrorException || rethrow ()
170
- error [] = e
170
+ error_ref [] = e
171
171
return Δin, Δout, :error
172
172
end
173
173
end
@@ -243,6 +243,27 @@ DoubleFrameDecoderStream(stream::IO; kwargs...) = TranscodingStream(DoubleFrameD
243
243
@test String (take! (sink)) == " [ ][ aabbcc ][ ddee ]"
244
244
end
245
245
246
+ @testset " Issue #160 Safely close stream after failure" begin
247
+ sink = IOBuffer ()
248
+ stream = TranscodingStream (DoubleFrameDecoder (), sink)
249
+ write (stream, " abc" )
250
+ @test_throws ErrorException (" expected [" ) close (stream)
251
+ @test ! isopen (stream)
252
+ @test ! isopen (sink)
253
+
254
+ @testset " nested decoders" begin
255
+ sink = IOBuffer ()
256
+ stream = TranscodingStream (DoubleFrameDecoder (), sink)
257
+ stream2 = TranscodingStream (DoubleFrameDecoder (), stream)
258
+ write (stream2, " abc" )
259
+ # "expected byte" error with caused by "expected ["
260
+ @test_throws ErrorException (" expected byte" ) close (stream2)
261
+ @test ! isopen (stream2)
262
+ @test ! isopen (stream)
263
+ @test ! isopen (sink)
264
+ end
265
+ end
266
+
246
267
@testset " stop_on_end=true in nested streams" begin
247
268
s1 = DoubleFrameDecoderStream (DoubleFrameEncoderStream (
248
269
DoubleFrameDecoderStream (
0 commit comments