fix(diff): exit 2 on unreadable operand per POSIX diff convention#2473
Open
hgunduzoglu wants to merge 1 commit into
Open
fix(diff): exit 2 on unreadable operand per POSIX diff convention#2473hgunduzoglu wants to merge 1 commit into
hgunduzoglu wants to merge 1 commit into
Conversation
rtk diff read its operands with `?`, so a missing or unreadable file collapsed to exit 1 in main's error handler — indistinguishable from "files differ". POSIX diff reserves exit 2 for trouble (I/O errors), 1 for differences, 0 for identical. Read operands explicitly, print a diff-style message to stderr, and return 2 on failure. The differing-files case (exit 0 -> 1) was already fixed by rtk-ai#2394. Fixes rtk-ai#2446
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Completes #2446.
rtk diffnow follows the full POSIX diff exit-code convention:The differing-files row was resolved by #2394 (merged). This PR closes the remaining gap: I/O errors.
Root cause
run()read both operands with?. A read failure propagated up tomain()'s error handler, which returns exit 1 for anyErr— indistinguishable from "files differ". So a typo'd path or a deleted file was silently reported as a difference (exit 1) instead of trouble (exit 2).Fix
Read the operands explicitly via a small
read_operandshelper: on any I/O error it prints a diff-style message to stderr and returns exit code 2, mirroring systemdiff. No change to the identical/differ paths.Testing
CARGO_MANIFEST_DIRso they don't depend on cwd.cargo fmt --all --check && cargo clippy --all-targets && cargo test— clean, 2203 passed.difffor all three exit codes (0/1/2).No output-format change, so token savings are unaffected (the error path prints a one-line stderr message, same as before).