Skip to content

Commit 02272d9

Browse files
authored
fix(io): ignore BrokenPipe error in op_print (#31844)
1 parent bd6bce3 commit 02272d9

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

ext/io/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,9 +1199,11 @@ pub fn op_print(
11991199
) -> Result<(), JsErrorBox> {
12001200
let rid = if is_err { 2 } else { 1 };
12011201
FileResource::with_file(state, rid, move |file| {
1202-
file
1203-
.write_all_sync(msg.as_bytes())
1204-
.map_err(JsErrorBox::from_err)
1202+
match file.write_all_sync(msg.as_bytes()) {
1203+
Err(FsError::Io(io)) if io.kind() == ErrorKind::BrokenPipe => Ok(()),
1204+
other => other,
1205+
}
1206+
.map_err(JsErrorBox::from_err)
12051207
})
12061208
}
12071209

tests/integration/run_tests.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,7 +2481,7 @@ console.log("finish");
24812481
}
24822482

24832483
#[test]
2484-
fn broken_stdout() {
2484+
fn stdout_early_read_drop() {
24852485
let (reader, writer) = os_pipe::pipe().unwrap();
24862486
// drop the reader to create a broken pipe
24872487
drop(reader);
@@ -2497,10 +2497,9 @@ fn broken_stdout() {
24972497
.wait_with_output()
24982498
.unwrap();
24992499

2500-
assert!(!output.status.success());
2500+
assert!(output.status.success());
25012501
let stderr = std::str::from_utf8(output.stderr.as_ref()).unwrap().trim();
2502-
assert!(stderr.contains("Uncaught (in promise) BrokenPipe"));
2503-
assert!(!stderr.contains("panic"));
2502+
assert_eq!(stderr, "", "{:?}", stderr);
25042503
}
25052504

25062505
#[test]

0 commit comments

Comments
 (0)