Repository navigation
fix(print): surface external failures instead of masking exit code (#19227) - #19260
Conversation
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).
There was a problem hiding this comment.
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
Open (6)
do -i { ^cmd } | printnow fails Release notes for the behavior change. The PR body has no release-notes section, but scripts that pipe a failing external intoprintnow stop where they used to continue, for example^grep pat file | printwith no match, or a hook that runs^cmd | print. This happens withpipefail=falsetoo:^false | printnow errors like| collectdoes, while| linesstill exits 0. Exit code 1 doesn't show that the external's status got through^cmd | print <args>still hides the exit code with pipefail off The issue'sprint -ecase isn't tested These could be cases inpipefail_feature
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.
|
Pushed 2e144f6. I moved the two print tests into pipefail_feature with exact exit codes, so On
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. |
|
please respond to each review comment so we can make sure nothing is missed |
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
All six points from my last review are fixed. These are small leftovers.
Findings: 0
Open (3)
Innernu -cruns without--no-config-file --no-std-lib Output check doesn't coverprint -e PR body names a test that doesn't exist. The description listsprint_to_stderr_keeps_output_and_external_exit_code, but the test ispipefail_print_keeps_output_before_failure. "Tests run" also still listscargo test -p nu-command --test tests -- commands::print, and this PR no longer touches that file.
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.
|
Pushed ce770d6 with the three leftovers from your last review: inner |
|
Thanks |



Description
Fixes #19227.
printignored failures of external commands because it calledignore_error(true)on the child's byte streams, so a pipeline such as a failing external command piped intoprintexited 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 topipefail_feature(fail 30 | print,print --raw,print -e) pluspipefail_print_keeps_output_before_failureandpipefail_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
printhid the failure of an external command: a failing external command piped intoprintnow 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 | printwith no match now errors, anddo -i { ^false } | printnow fails likedo -i { ^false } | collectalready does.Additional notes
fixes #19227