summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authormelbourne2991 <4619280+melbourne2991@users.noreply.github.com>2024-08-20 10:21:12 +1000
committerGitHub <noreply@github.com>2024-08-20 00:21:12 +0000
commit0eba180fdbfdc19e15c743f00382d3fc79f65a10 (patch)
treeca6169345b4fa2352874413096088a9b2e7416c6 /cli
parent1c4db2aca93aa248e501ea2de9fe4b399eeb5cfd (diff)
fix(repl): Prevent panic on broken pipe (#21945)
Diffstat (limited to 'cli')
-rw-r--r--cli/tools/repl/mod.rs22
1 files changed, 17 insertions, 5 deletions
diff --git a/cli/tools/repl/mod.rs b/cli/tools/repl/mod.rs
index d754b4dd2..ed3d94c84 100644
--- a/cli/tools/repl/mod.rs
+++ b/cli/tools/repl/mod.rs
@@ -1,5 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+use std::io;
+use std::io::Write;
+
use std::sync::Arc;
use crate::args::CliOptions;
@@ -241,15 +244,24 @@ pub async fn run(
// Doing this manually, instead of using `log::info!` because these messages
// are supposed to go to stdout, not stderr.
+ // Using writeln, because println panics in certain cases
+ // (eg: broken pipes - https://github.com/denoland/deno/issues/21861)
if !cli_options.is_quiet() {
- println!("Deno {}", crate::version::DENO_VERSION_INFO.deno);
- println!("exit using ctrl+d, ctrl+c, or close()");
+ let mut handle = io::stdout().lock();
+
+ writeln!(handle, "Deno {}", crate::version::DENO_VERSION_INFO.deno)?;
+ writeln!(handle, "exit using ctrl+d, ctrl+c, or close()")?;
+
if repl_flags.is_default_command {
- println!(
+ writeln!(
+ handle,
"{}",
colors::yellow("REPL is running with all permissions allowed.")
- );
- println!("To specify permissions, run `deno repl` with allow flags.")
+ )?;
+ writeln!(
+ handle,
+ "To specify permissions, run `deno repl` with allow flags."
+ )?;
}
}