Skip to content

fix(diag): route compgen -F error via builtin stderr; honor gnu_errfmt - #1131

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/diag-routing
Oct 23, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/diag-routing

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #1041, closes #1038. (1) compgen -F missing-function diagnostic bypassed all redirections via session-stderr eprintln (and out of order); now goes through the caller's stderr buffer after the -F warning, matching GNU pcomplete.c internal_error routing. (2) gnu_errfmt was in the shopt table but never queried; new error_prefix()/parser_error_prefix() (+comsub variants) gate error.c's error_prolog/parser_error families (command-not-found, arith evalerror, redirect errors, wait pid, readonly/badsubscript/unbound/nameref, parser/syntax/heredoc), while builtin-family messages (cd, compgen warning, jobs, declare sh_readonly...) stay ungated per GNU builtins/common.c. Tests: lib 693 + 6 new + 60+ redirect/arith/parse/nounset/declare/heredoc/trap suites green, executor_tests delta-free vs base; GNU parity byte-identical incl. rc and redirect files. Known gaps (pre-existing, unchanged): declare -a/-A/-i/-l/-u compound on readonly; tempenv/read cmd: segment.

…r gnu_errfmt (rubash#1041, rubash#1038)

bypassing the builtin's redirects and emitting before the buffered -F
warning. Route the pcomplete.c:1058-1066 internal_error diagnostic
through the caller's stderr buffer so `compgen -F f -- "" 2>e.txt
>o.txt` lands both lines in e.txt in order (rc 1, o.txt empty).

error_prefix()/parser_error_prefix() (+ _for_line twins, comsub
variant) implementing the error.c:83 / :300-316 gate (`file:N: ` vs
`file: line N: `), and switch the whole error_prolog/parser_error
family onto it: command-not-found/slash-execve (execute_cmd.c
internal_error), arithmetic evalerror/bad-substitution (expr.c,
subst.c report_error), redirection_error (redir.c:135), wait pid
(jobs.c JWAIT_PERROR), err_readonly/err_badarraysub/err_unboundvar
(error.c), nameref warnings (internal_warning), parser/syntax errors
and heredoc warnings (parser_error/report_syntax_error). Builtin
errors (common.c builtin_error_prolog: cd, compgen warning, jobs,
declare sh_readonly, sh_chkwrite, select/read invalid-id) keep the
ungated prefix — verified against GNU 5.3.20, including the compgen
split (warning ungated, lookup gated) and the wait split.

New tests: tests/issue1041_compgen_missing_function_redirect.rs,
tests/issue1038_gnu_errfmt_prefix.rs. Verified: lib 693 green, new
tests green, related integration suites green, executor_tests delta
vs base is timing flakes only (kill/ulimit/signal-number cases fail
identically on unmodified base on this box). Debug + release
binaries both reproduce GNU byte-for-byte on the issue scripts.

Known gaps (unchanged from base, C ownership unsettled):
- `declare -a/-A/-i/-l/-u <compound>` on readonly reports ungated
  bare while `declare <compound>` gates; both collapse into one
  rubash pre-check (kept ungated = old behavior).
- `t=X cmd` tempenv / `read v` readonly carry a `cmd: ` segment GNU
  omits (pre-existing); only the line segment is now gated.
@caomengxuan666
caomengxuan666 merged commit 0865252 into master Oct 23, 2026
6 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member Author

Rebased onto post-#1181 master and force-pushed as 6c6d523f. Conflicts: kept master's fd-2 routing (arith_diag, #1127) while adopting this PR's error_prefix() (error_prolog family, gnu_errfmt) at the arithmetic / wait / command-not-found sites — orthogonal fixes, both kept. Also: master's mid-command flush + this PR's builtin-stderr routing meant a second 2> open truncated the first flush and dropped the compgen -F warning; the early flush now only runs when a real -F function / -C command will execute (ordering per #1090). Known master-side issue unchanged: compgen -F realfunc 2>file still loses the warning to the same double-flush truncate. New test files' expected script names normalized via shell_pwd_display_path for Windows path form.

@caomengxuan666
caomengxuan666 deleted the fix/diag-routing branch October 23, 2026 04:53
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.

[bug] compgen -F <missing-func> error escapes all redirections [bug] shopt -s gnu_errfmt ignored

1 participant