mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 23:34:47 -05:00
fix(core): don't panic on stdout/stderr write failures in Deno.core.print (#11039)
This commit is contained in:
parent
188222b893
commit
580c9f9ef0
2 changed files with 25 additions and 2 deletions
|
@ -3230,6 +3230,29 @@ console.log("finish");
|
||||||
util::test_pty(args, output, input);
|
util::test_pty(args, output, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn broken_stdout() {
|
||||||
|
let (reader, writer) = os_pipe::pipe().unwrap();
|
||||||
|
// drop the reader to create a broken pipe
|
||||||
|
drop(reader);
|
||||||
|
|
||||||
|
let output = util::deno_cmd()
|
||||||
|
.current_dir(util::root_path())
|
||||||
|
.arg("eval")
|
||||||
|
.arg("console.log(3.14)")
|
||||||
|
.stdout(writer)
|
||||||
|
.stderr(std::process::Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.unwrap()
|
||||||
|
.wait_with_output()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert!(!output.status.success());
|
||||||
|
let stderr = std::str::from_utf8(output.stderr.as_ref()).unwrap().trim();
|
||||||
|
assert!(stderr.contains("Uncaught BrokenPipe"));
|
||||||
|
assert!(!stderr.contains("panic"));
|
||||||
|
}
|
||||||
|
|
||||||
itest!(_091_use_define_for_class_fields {
|
itest!(_091_use_define_for_class_fields {
|
||||||
args: "run 091_use_define_for_class_fields.ts",
|
args: "run 091_use_define_for_class_fields.ts",
|
||||||
output: "091_use_define_for_class_fields.ts.out",
|
output: "091_use_define_for_class_fields.ts.out",
|
||||||
|
|
|
@ -61,10 +61,10 @@ pub fn op_print(
|
||||||
is_err: bool,
|
is_err: bool,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
if is_err {
|
if is_err {
|
||||||
eprint!("{}", msg);
|
stderr().write_all(msg.as_bytes())?;
|
||||||
stderr().flush().unwrap();
|
stderr().flush().unwrap();
|
||||||
} else {
|
} else {
|
||||||
print!("{}", msg);
|
stdout().write_all(msg.as_bytes())?;
|
||||||
stdout().flush().unwrap();
|
stdout().flush().unwrap();
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue