summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormuddlebee <anweshknayak@gmail.com>2024-07-10 04:27:00 +0530
committerGitHub <noreply@github.com>2024-07-09 22:57:00 +0000
commit9776a13e33bc371a67f0d44925e2bf04dca159f1 (patch)
tree6419d25d2f51affe271018c7b55e1cf66641506b
parentfb6348500ffc827b3aaca3e8299e1a3964be43c1 (diff)
fix: panic when piping "deno help" or "deno --version" (#22917)
Fixes #22863 --------- Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
-rw-r--r--cli/main.rs3
-rw-r--r--tests/specs/cli/help_and_version_broken_pipe/__test__.jsonc9
-rw-r--r--tests/specs/cli/help_and_version_broken_pipe/deno.json6
-rw-r--r--tests/specs/cli/help_and_version_broken_pipe/help.out2
-rw-r--r--tests/specs/cli/help_and_version_broken_pipe/version.out2
5 files changed, 21 insertions, 1 deletions
diff --git a/cli/main.rs b/cli/main.rs
index 3368a06fc..8ae83e735 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -347,7 +347,8 @@ fn resolve_flags_and_init(
if err.kind() == clap::error::ErrorKind::DisplayHelp
|| err.kind() == clap::error::ErrorKind::DisplayVersion =>
{
- err.print().unwrap();
+ // Ignore results to avoid BrokenPipe errors.
+ let _ = err.print();
std::process::exit(0);
}
Err(err) => exit_for_error(AnyError::from(err)),
diff --git a/tests/specs/cli/help_and_version_broken_pipe/__test__.jsonc b/tests/specs/cli/help_and_version_broken_pipe/__test__.jsonc
new file mode 100644
index 000000000..775293571
--- /dev/null
+++ b/tests/specs/cli/help_and_version_broken_pipe/__test__.jsonc
@@ -0,0 +1,9 @@
+{
+ "steps": [{
+ "args": "task help",
+ "output": "help.out"
+ }, {
+ "args": "task version",
+ "output": "version.out"
+ }]
+}
diff --git a/tests/specs/cli/help_and_version_broken_pipe/deno.json b/tests/specs/cli/help_and_version_broken_pipe/deno.json
new file mode 100644
index 000000000..07763de46
--- /dev/null
+++ b/tests/specs/cli/help_and_version_broken_pipe/deno.json
@@ -0,0 +1,6 @@
+{
+ "tasks": {
+ "help": "deno help | echo",
+ "version": "deno --version | echo"
+ }
+}
diff --git a/tests/specs/cli/help_and_version_broken_pipe/help.out b/tests/specs/cli/help_and_version_broken_pipe/help.out
new file mode 100644
index 000000000..58d69d2ee
--- /dev/null
+++ b/tests/specs/cli/help_and_version_broken_pipe/help.out
@@ -0,0 +1,2 @@
+Task help deno help | echo
+
diff --git a/tests/specs/cli/help_and_version_broken_pipe/version.out b/tests/specs/cli/help_and_version_broken_pipe/version.out
new file mode 100644
index 000000000..75d015844
--- /dev/null
+++ b/tests/specs/cli/help_and_version_broken_pipe/version.out
@@ -0,0 +1,2 @@
+Task version deno --version | echo
+