Skip to content

fix(print): surface external failures instead of masking exit code (#19227) - #19260

Merged
fdncred merged 4 commits into
nushell:mainfrom
manish-9245:fix/19227-print-exit-code
Oct 21, 2026
Merged

fdncred merged 4 commits into
nushell:mainfrom
manish-9245:fix/19227-print-exit-code

Conversation

@manish-9245

@manish-9245 manish-9245 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #19227. print ignored failures of external commands because it called ignore_error(true) on the child's byte streams, so a pipeline such as a failing external command piped into print exited with 0 while the same failure from an internal command exited with 1. This removes the suppression so non-zero exits propagate. Tests were added to pipefail_feature (fail 30 | print, print --raw, print -e) plus pipefail_print_keeps_output_before_failure and pipefail_print_stderr_keeps_output_before_failure, which check that output still reaches stdout / stderr before the failure exit code.

^cmd | print <args> still drops the piped input without waiting on the child, so with pipefail off it still exits 0, the same as | ignore.

Tests run: cargo test --test tests -- pipefail_feature, cargo clippy --tests, cargo fmt --all -- --check.

User-facing changes (Release notes)

Fixed an issue where print hid the failure of an external command: a failing external command piped into print now makes the pipeline fail with its non-zero exit code instead of exiting with 0. This is a behavior change for scripts that relied on the old result, for example ^grep pat file | print with no match now errors, and do -i { ^false } | print now fails like do -i { ^false } | collect already does.

Additional notes

fixes #19227

Fixes nushell#19227. print ignored external command failures via ignore_error(true) on child byte streams, so pipelines like '^cat /nonexistent | print' exited 0. Remove the suppression so non-zero exits propagate like internal commands.

Tests: cargo test --package nu-command --test tests -- commands::print (6 passed); cargo build (ok); cargo clippy -p nu-cli (ok); cargo fmt --check (ok).

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review overview

🟡 Changes recommended

Removing the ignore_error(true) is the right fix for #19227, but it also makes do -i { ^cmd } | print fail, and the behavior change needs release notes.

Findings: 1 High severity · 2 Medium severity · 3 Low severity

Open (6)

Notes from my clanker, checked on 8fd35b1. I built the branch and ran cargo test -p nu-command --test tests -- commands::print (6 passed). I also compared ^cmd | print, do -i { ^cmd } | print, and signal-killed children against main 776da6d, with pipefail on and off.

Comment thread crates/nu-cli/src/commands/print.rs Resolved
Comment thread crates/nu-cli/src/commands/print.rs Resolved
@manish-9245

Copy link
Copy Markdown
Contributor Author

Pushed 2e144f6. I moved the two print tests into pipefail_feature with exact exit codes, so fail 30 | print, print --raw and print -e now all assert 30. The release notes section now says this is a behavior change and gives examples.

On do -i { ^cmd } | print: I did not touch do. The fix there is in the -i arm of do_.rs and it changes what let x = do -i { ^false } does, so that is your call. For now the release notes say it now fails like | collect already does. I can open a follow-up if you want do -i to ignore the child regardless of where stdout goes.

^cmd | print aa with pipefail off still exits 0 because print drops the input, same as | ignore. It is mentioned in the description.

I tried a test that checks the output still shows before the error, but it was not reliable in the test harness, so I left it out.

@fdncred

fdncred commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

please respond to each review comment so we can make sure nothing is missed

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review overview

🟡 Changes recommended

All six points from my last review are fixed. These are small leftovers.

Findings: 0 High severity · 0 Medium severity · 3 Low severity

Open (3)

Notes from my clanker, checked on 17e8820. I built the branch and ran cargo test --test tests -- pipefail (11 passed, and 15 of 15 runs in a loop). With the old ignore_error(true) put back in print.rs, the three new pipefail_feature cases and pipefail_print_keeps_output_before_failure all fail, so they catch the bug.

@manish-9245

Copy link
Copy Markdown
Contributor Author

Pushed ce770d6 with the three leftovers from your last review: inner nu flags, a print -e stderr test, and the PR body now names the right tests and drops the stale commands::print command. Replied on each inline thread.

@fdncred
fdncred merged commit d1064f1 into nushell:main Oct 21, 2026
11 checks passed
@fdncred

fdncred commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Thanks

@github-actions github-actions Bot added this to the v0.117.0 milestone Oct 21, 2026
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

print masks exit codes for external commands

2 participants