Skip to content

awk: exit with 1 when the program does not parse - #191

Merged
Alonely0 merged 3 commits into
uutils:mainfrom
HarpeLm:fix/syntax-error-exit-status
Nov 20, 2026
Merged

Alonely0 merged 3 commits into
uutils:mainfrom
HarpeLm:fix/syntax-error-exit-status

Conversation

@HarpeLm

@HarpeLm HarpeLm commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #165

When the program did not parse, uu_main flushed the diagnostics and returned Ok(()), so awk exited with 0 and awk '...' || handle_error never saw the failure. It now exits through exit_err with EXIT_FAILURE (1), the status for errors before the program runs (as discussed in #184; fatal runtime errors exit with 2 since #186). The diagnostic output is unchanged.

This covers both a program given on the command line and one read with -f, since both go through the same Err(diagnostics) branch.

Tests

  • syntax_error_exits_one: the issue's program plus three other syntax errors (print (, an unclosed BEGIN {, $ without an operand); each exits with 1, prints nothing on stdout and reports Syntax error.
  • syntax_error_in_a_program_file_exits_one: the same through -f bad.awk.
  • syntax_error_does_not_run_the_program: a syntax error in END stops the program before its BEGIN rule runs.

Without the change in src/main.rs, all three fail.

  • cargo test --workspace: all pass
  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets -- -D warnings

@Alonely0 Alonely0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hello! Thanks for the fix! Looks great, but I will rebase the branch and push a commit since the signature of exit_err changed after the last merge.

Comment thread tests/by-util/test_awk.rs Resolved
@Alonely0
Alonely0 force-pushed the fix/syntax-error-exit-status branch from 25afecb to f8bf1a4 Compare November 19, 2026 23:50
@Alonely0
Alonely0 merged commit fee19de into uutils:main Nov 20, 2026
12 of 18 checks passed
@Alonely0

Copy link
Copy Markdown
Collaborator

Thank you so much for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

awk: a syntax error exits with status 0

3 participants