Repository navigation
fix(source): source 边界上的语法错误中止降级为 reader discard,不再终止会话(#451 类 B) - #481
Merged
Merged
Conversation
… not an exit jump (rubash#451 class B) GNU evalstring.c parse_and_execute aborts the remaining sourced text on a syntax error as an ORDINARY failure (evalstring.c:585-601, no jump_to_top_level), so the sourcing driver keeps reading: an interactive shell reports the diagnostic and prompts again, a non-interactive script continues with its next command (verified WSL GNU 5.3.0). The engine recorded that abort's ExitCode(2) as a reader exit jump (run_source_impl's execute_ast arm) while the source builtin consumed the parse-error flag that classifies it (execute_source_with_args' tail handler and run_source_groups' two abort arms), so every driver gate of the shape 'exit_jump && !parse_error' read a reader-discard as a real exit: the interactive session died right after the diagnostic — the eco hang:enter1 family, where the first probe line typed after 'source <file>' never ran (Kohei-Wada/dotfiles bin/update-nvim.sh, sloria/doitlive examples/walkthrough.sh shapes) — and non-interactive scripts aborted with rc 2 where GNU continues. When the source boundary consumes a parse-error abort it now consumes the recorded jump with it (a real 'exit' inside the file returns Err with the flag clear and still unwinds, pinned by regression). New suite tests/issue451_source_parse_discard_regressions.rs pins the unclosed if/function/backtick tails, the trailing | and && connectors, the non-interactive continue, and the two exit-still-wins cases.
This was referenced Oct 10, 2026
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.
closes #451
问题(类 B:
hang:enter1)source <file>结束后,交互会话对第一条后续输入无响应(eco 签名hang:enter1:ECO>;样本:Kohei-Wada/dotfiles@264319ebin/update-nvim.sh、sloria/doitlive@168333bexamples/walkthrough.sh)。根因
不是 continuation 状态残留,而是 source 边界上的中止分类错误。GNU
evalstring.cparse_and_execute 对 sourced 文件的语法错误按普通失败中止剩余文本(evalstring.c:585-601,无 jump_to_top_level):交互 shell 报错后继续读下一条(WSL GNU 5.3.0 实测),非交互脚本继续执行后续命令。引擎里
run_source_impl的 execute_ast 分支把该中止的 ExitCode(2) 记成 reader exit jump,而sourcebuiltin(execute_source_with_args尾部 handler 与run_source_groups的两个中止分支)消费掉了解分类用的 parse-error 标志。于是所有exit_jump && !parse_error形状的驱动闸门把 reader-discard 误读成真实exit:printf 'source bad\necho AFTER\n' | bash打印 AFTER,rc 0)。触发形态:sourced 文件尾部带不完整构造——未闭合
if/f() {、行尾|/&&、未闭合反引号块(walkthrough 的 ```python 围栏正是此形态)。最小复现(修复前):修复
source 边界消费 parse-error 中止时同步消费其记录的 exit jump(三处:incomplete-group 分支、complete-group 分支、
execute_source_with_args尾部)。文件内真实exit走parse_error == false路径返回 Err,仍正常 unwind(exit 5/exit 7语义由回归钉死)。验证
tests/issue451_source_parse_discard_regressions.rs(8 用例):未闭合 if/函数体/反引号块尾、行尾|/&&、非交互继续、exit 仍生效×2;全部通过。source walkthrough.sh后echo ECOSRC修复前被吞、修复后正常执行。interactive_syntax_error_does_not_end_session、issue426 sourced_exit、issue433 prompt_command)。cargo test --lib中 2 个失败(pwd 盘符格式、/mnt/c 解析)在干净 HEAD 上同样失败,为环境相关预存问题,与本单无关。注:eco 重跑中 update-nvim.sh 现判 SLOW(下载耗时)、walkthrough.sh 判 upstream-heavy-external(>15s 外部命令循环),triage 记录见 docs/audit/findings/wt98b-goldtri-triage-results.json;本修覆盖其中引擎侧真因(会话被误杀),外部耗时因素不属引擎范围。