Skip to content

Commit 8808788

Browse files
committed
std/io: fix ReadAll will always ignore errors
1 parent f39de10 commit 8808788

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

std/io/io.jule

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,13 @@ async fn ReadAll(mut r: Reader)!: []byte {
426426
// Invariant: finalSize = sum(len(c) for c in chunks)
427427
let mut finalSize: int
428428
for {
429-
n := r.Read(b[len(b):cap(b)]).await else { break }
429+
n := r.Read(b[len(b):cap(b)]).await else {
430+
// If any data was read, ignore the error and return the data.
431+
if len(chunks) > 0 || len(b) > 0 {
432+
break
433+
}
434+
error(error)
435+
}
430436
if n == EOF {
431437
break
432438
}
@@ -439,6 +445,8 @@ async fn ReadAll(mut r: Reader)!: []byte {
439445
next += next / 2
440446
}
441447
}
448+
// On error this condition must be true: len(chunks) > 0 || len(b) > 0
449+
// On EOF, len(chunks) and len(b) may be zero.
442450
if len(chunks) == 0 {
443451
ret b
444452
}

0 commit comments

Comments
 (0)