Skip to content

executor: port line_number_for_err_trap for ERR-trap LINENO (Refs #3553) - #3602

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3553-err-trap-lineno
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3553-err-trap-lineno

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Ports GNU's line_number_for_err_trap (execute_cmd.c:291): a second line tracker written only by SET_LINE_NUMBER sites — leaf stamps (simple :936, subshell :696, arith :3904, cond :4138) and the ambient pins (pipeline :2895, misc-compound frame :1141) — so a compound command's OWN redirect failure (execute_cmd.c:854-883) reports the last stamped line instead of the compound's.

  • err_trap_line stamped in set_current_line ahead of the ambient env write: leaf kinds stamp their own line; pipeline/arith/cond/function_def pin to the last stamped line.
  • (( )) and [[ ]] re-stamp their own line once their own redirections have bound (:3904/:4138).
  • execute_function saves/restores the tracker across the call (:5242) so a failing call reports the call line.
  • The [upstream] Traps: ERR trap does not fire on a redirection error of a compound command (set -e consequence also missing) #2659 marked-redirect-failure conversion now sets err_trap_fired_at_dispatch as its comment already promised, closing a double fire for [[ x = x ]] </bad.

Pins: tests/issue3553_err_trap_lineno.rs — previous-leaf reporting, the full compound matrix, the cond single-fire, and the function-frame restore — all byte-identical to vendored GNU 5.3.20; neighboring trap/LINENO suites stay green.

Refs #3553

…3553)

GNU keeps a second line tracker, line_number_for_err_trap
(execute_cmd.c:291), written only by SET_LINE_NUMBER (skipped while the
ERR trap is in progress) at the leaf stamp sites — simple :936,
subshell :696, arith :3904, cond :4138 — and by the ambient pins at
pipeline :2895 and the misc-compound frame :1141. The :854-883
redirect-failure arm binds that tracker into line_number for
run_error_trap, so a compound's OWN redirect failure reports the last
stamped line, not the compound's: `{ :; } </bad` names the previous
leaf, arith/cond name the ambient line, and inside a function the
failing call reports the CALL line because execute_function
unwind-protects the tracker (execute_cmd.c:5242).

Mirror it with err_trap_line, stamped in set_current_line before the
ambient env write: leaf kinds stamp their own line, pipeline and the
arith/cond/function_def frame pin to the last stamped line
(__RUBASH_CURRENT_LINE before this command's stamp); arith and cond
also stamp their own line once their own redirections have bound
(:3904/:4138), and execute_function saves/restores the tracker across
the call (:5242). The consumed value replaces command.line in the ERR
action's $LINENO pin (execute_cmd.c:873).

Also close the double fire the issue's matrix exposed: the #2659
marked-redirect-failure conversion already promised the
fired-at-dispatch record in its comment but never set it, so the list
loop's own adjudication look ran the trap again for `[[ x = x ]] </bad`;
set err_trap_fired_at_dispatch after the conversion fire.

Pins: tests/issue3553_err_trap_lineno.rs — previous-leaf reporting,
the full compound matrix, the cond single-fire, and the
function-frame restore — all byte-identical to vendored GNU 5.3.20;
neighboring trap/LINENO suites (2659/720/846/2117/1162-1166/1171/
1661/2202/2332/2281/1720) stay green.

Refs #3553

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3602 第1轮 — 建议:PASS
head: eb910f7 base(merge-base): 96802ca 文件: 12 个 +240/-2
关联 issue: #3553(状态:open,我核过的时间:2026-11-15 本地)

机制核查:

  • 移植 GNU execute_cmd.c:291 line_number_for_err_trap + SET_LINE_NUMBER(:293-298) 双轨行号:err_trap_line 仅在 leaf 戳记点(simple/subshell)与 ambient pin(pipeline/arith/cond/function_def 入口)写入;trap_exec.rs 的 failed_line 改为 line_override.or_else(err_trap_line).or(command.line) → 复合命令自身重定向失败报「上一个叶子的行」。arith/cond 在自身重定向绑定后重戳 own line(GNU :3904/:4138),execute_function 跨调用 save/restore(GNU :5242)。另把 [upstream] Traps: ERR trap does not fire on a redirection error of a compound command (set -e consequence also missing) #2659 marked-redirect 转换补记 err_trap_fired_at_dispatch,消 [[ x = x ]] </bad 双发(base 实测确有双发)。属忠实移植,非黑名单补丁。
  • 无关改动:无(11 个源文件均为戳记点/存取器接线)。

腿:

  • 钉自跑(head):issue3553_err_trap_lineno 4 passed / 0 failed。
  • fail-first(base 96802ca):同 stem 0 passed / 4 failed;红名 = 全部 4 钉——base 报复合自身行({ :; } </bad 报 ERR@4 而非 GNU 的 ERR@3),matrix 报 4,5,6,7,9,10,10,11(含 cond 双发)vs GNU 3,3,3,3,8,8,11,函数帧报体行而非调用行。与 PR 声称缺陷完全一致。
  • lib 双边:以 CI head 腿代——Linux 腿红集 {issue2875}、macOS 腿 {issue2875}(1243/1247)、goldens 腿 {issue2875}(1350/1354);均基线,差集 ∅。
  • 卫生:rustfmt --check 12 文件 OK。
  • CI:红腿 3 个,红名各仅 issue2875(基线);其余腿全绿。
  • GNU 对照:wsl bash 5.3.20(1)-release,脚本 target/p-3553{a..d}.sh,四形状逐字节一致:
    • a brace-group:x\nERR@3\ny\ndone ✓
    • b 全矩阵:ERR@3×4 + arith-continue + ERR@8×2 + ERR@11 + last ✓
    • c cond 单发:ERR@3\ndone ✓
    • d 函数帧恢复:body1\nafter\nsep1\ng1\nERR@11\nsep2\nERR@13\nsep3\nERR@17\nsep4\nERR@18\ntail ✓

F 点:无

未跑/VOID 的腿:本地全量 lib 与 -D warnings 未跑(以 CI head 腿红集 + 编译/钉跑通代替判读)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【队长终裁】PASS

核过审计报告(6886872456)+ CI 全表。钉 4/4,fail-first 0/4(全红,症状与 issue 完全一致:base 报复合自身行,{ :; } </bad 报 ERR@4 而非 GNU 的 ERR@3;矩阵 4,5,6,7,9,10,10,11 vs GNU 3,3,3,3,8,8,11);GNU oracle 四形状逐字节一致(含 cond 单发与函数帧恢复);12 文件 fmt 全 OK;CI 三红红名全为 issue2875 基线。属忠实移植(execute_cmd.c:291 line_number_for_err_trap + SET_LINE_NUMBER 双轨行号)。合入条件:合入轮补跑 lib 双边 + RUSTFLAGS="-D warnings" 全量(agent 未跑)。合入意义:本单合入即解 #3327 的定序(其 ERR 面须按本单合入后形状重推)——#3327 重派随本单合入后启动(fresh 全量守卫扫描)。合入正文 Refs #3553(合入后由队长手动关闭)。

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.

1 participant