Repository navigation
Stamp the diagnostic frame file so sourced-file functions report their definition file (Refs #3035) - #3047
Merged
Conversation
GNU's diagnostic prolog name is get_name_for_error (error.c:90-120): BASH_SOURCE[0], which at a function call is the function's DEFINITION file (make_cmd.c:746-771 records source_file from BASH_SOURCE[0] at definition time; execute_cmd.c:5310-5313 pushes it at call entry). The executor's own prefix already read that composed view (#2212), but the builtin layer's private diagnostic_prefix copies paired the per-frame __RUBASH_CURRENT_LINE with the top-level-only __RUBASH_SCRIPT_NAME, so an error inside a function defined in a sourced file carried the definition file's line under the top-level script's name. The stored BASH_SOURCE mirror refreshes only at source-frame push/pop, so env-only builtins cannot derive the frame file themselves. Following the __RUBASH_CURRENT_LINE carrier idiom: - set_current_line also stamps __RUBASH_CURRENT_FILE (= current_error_file_name(), the same composed view diagnostic_prolog reads) into both storages under the same equality gates; init strips it beside the line for non-respawn entries. - New shared builtins::diagnostic builders replace the private copies in test/ulimit/trap/cd/exec (cd's readonly twin too). - script_name_prefix takes error_report_name() instead of preferring __RUBASH_SCRIPT_NAME.
Six cells: the seed (test error inside a sourced-file function), the same error reached through a caller function, a top-level-defined control, and the ulimit/cd/trap faces of the same builtin_error family. Expectations were verified against GNU bash 5.3.20 by probe first: 5 of 6 fail on the base tree (the control passes); all 6 pass with the carrier stamp.
caomengxuan666
marked this pull request as ready for review
November 8, 2026 01:06
caomengxuan666
added a commit
that referenced
this pull request
Nov 8, 2026
…2885) - markers.rs census: add EXACT entry for __RUBASH_CURRENT_FILE (new carrier from #3035/#3047, missing from the E8 census). - marker_registry_roundtrips: remove all four TYPED_DATA_EXCEPTIONS (E002 shapes 1-3 fixed by #2882/#3006; E316 shape 3 by #3016/#3041); the stem now asserts every shape round-trips. - marker-lint-allowlist: delete the two #2882 KNOWN BLIND SPOT entries (their own text said delete when #2882 lands), plus two entries made stale by master-side changes: set.rs ESC rendering entry (#3044 restructured the table) and command_prepare contains:QUOTED_NULL_MARKER (#3006 converted those consumers to E400-aware helpers). - marker_leak_golden_pty: un-ignore the read -p cell (#3001 landed the read -p decode). - marker_leak_golden: set-listing C0 scalar cell now expects the ansic-quoted GNU form (rubash#3017/#3044), byte-verified against GNU bash 5.3.20; the no-marker assertion is unchanged. Verified on the merged tree (merge bd87ed1 + this commit): lint OK (117 consts / 258 sites), registry 10/0, PTY 2/0, golden 20/0, lib 1200/0/4, -D warnings rc=0, hygiene/fmt/CR clean.
caomengxuan666
added a commit
that referenced
this pull request
Nov 9, 2026
…#3143) Fixes #2907 生态链钉入仓:真实 git contrib 脚本(git-completion.bash / git-prompt.sh,GPL 不入仓、宿主发现)的 live 入口端到端链钉——链 A 驱动已注册补全入口 `__git_wrap__git_main`(含 A15 直调 `__git_main`),链 B 在八态仓库上渲染 `__git_ps1`(含无参打印形与 pcmode 形);同仓库、同 driver 分别在 rubash 与 GNU bash 5.3.20 oracle 下运行,stdout 逐字节一致、stderr 归一脚本路径后逐字一致。同文件第二钉复核 mvdan-n 16 个解析夹具的 `-n` 退出码与 oracle 逐个一致(559 片段差分是否接 CI 仍归 #3033 裁定,本 PR 不预断)。本钉即 eco-2907 两处已修分歧的链级回归钉:B6 格 = #3034(PR #3056)真实命中形,A15 stderr 格 = #3035(PR #3047)真实命中形。 本 PR 删除了什么:无(纯测试与夹具新增)。净行数 +645/−0,4 文件:tests/issue2907_git_contrib_chain.rs、tests/fixtures/ecosuite/git-contrib/{driver,make-repos}.sh、tests/fixtures/ecosuite/MANIFEST.md。
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.
UNVERIFIED-BY-CAPTAIN
Refs #3035
问题
sourced 文件里定义的函数在执行期报错时,rubash 报顶层脚本的文件名
(行号却是定义文件内的行)。GNU 报定义文件:
./errlib.sh: line 3: [: 1: unary operator expectedc4f397d6):isolate-err.sh: line 3: [: 1: unary operator expected链路面同根:git-contrib 链 A15(GNU
git-completion.bash: line 3489vs rubash
driver.sh: line 3489)。根因
帧机制本身是对的:函数体内
${BASH_SOURCE[0]}已是定义文件(定义时记录 + 调用入场推帧都正确,探针核实)。
错的是 builtins 层一批私有的
diagnostic_prefix(env_vars)拷贝:它们把逐帧维护的
__RUBASH_CURRENT_LINE(行,对)与顶层粒度的__RUBASH_SCRIPT_NAME(名,错)拼成{script}: line {line}:。这正是 executor 侧前缀在 #2212 修过的「行对名错」配对,只是这批
builtins 私有拷贝从未接上。它们接不上也有结构原因:存储的
BASH_SOURCE 镜像只在 source 帧 push/pop 时刷新,函数入场不刷,
env-only 的 builtin 函数读不到活的帧文件——缺一个由 executor
逐命令维护的文件载体。
GNU 锚点
error.c:90-120 get_name_for_error:非交互 prolog 名 =BASH_SOURCE[0](非空时),否则 $0 / shell 名。
make_cmd.c:746-771 make_function_def:定义时FUNCTION_DEF.source_file = BASH_SOURCE[0]。execute_cmd.c:5310-5313 execute_function:调用入场push_source(..., shell_fn->source_file)——帧文件是定义文件,与调用者无关(wrapper 跨文件调用格据此仍报定义文件)。
修法(机制)
完全仿
__RUBASH_CURRENT_LINE的既有范式:Executor::set_current_line(ast_exec 循环与 funnel 的共同戳点)盖行戳的同时盖
__RUBASH_CURRENT_FILE,值 =current_error_file_name()(组合 BASH_SOURCE[0],即diagnostic_prolog用的同一个名字来源,不另立第二套语义);双存储(env map + 进程 env 镜像)、等值门(新缓存字段
file_env_os_value与line_env_os_value同型);名字为空时摘除载体,读取侧回退
__RUBASH_SCRIPT_NAME。init.rs两处剥离点与 CURRENT_LINE 并排加 CURRENT_FILE(validated respawn 子代保留盖戳,与行帧同规则)。
src/builtins/diagnostic.rs(
diagnostic_prefix/ gnu_errfmt 门的readonly_error_prefix),本波转换无在飞车道占用的拷贝:test、ulimit、trap、cd(两 fn)、
exec;executor 侧
script_name_prefix的名字来源改为error_report_name()。*_for_line等)经调用方审计均为读流/记录行语义,名字与记录行同源,不在本 PR 面内。
回归钉
tests/issue3035_sourced_function_error_file_regressions.rs(6 格):issue 种子(
[于 sourced 函数)、wrapper 跨文件调用、顶层自有函数对照、ulimit / cd / trap 同族三面。期望值均先经 GNU 5.3.20
探针钉死。
车道自报(待队长复核):
顶层名、right 为 GNU 的
./errlib*.sh;修后 6/6 绿。c4f397d6)1197/0/4。RUSTFLAGS="-D warnings" cargo check --locked --lib --bins过。报错 / 顶层报错 3 格与 GNU 逐字节一致(含 rc)。
issue2947 6/0 全绿。issue1768 为 4/2,但 base 树同茎同为 4/2
(两红格均既存:
-c格期望bash:先于 [B1-11] Diagnostic prolog hardcodesbashinstead of the argv[0]-derived name (owner decision: impersonation vs fidelity) #2714 的 argv0 prolog裁定;前台死亡通知行号为收割时点敏感)——本 PR 零新增红,
该茎期望订正不在本 PR 面内,一并报队长。
本 PR 删除了什么
diagnostic_prefix/readonly_error_prefix拷贝,统一到src/builtins/diagnostic.rs的共享实现。HashMapimport;test.rs 两个死平台 cfg stub 的签名由
&HashMap对齐为活变体的&VarTable(调用方本就传 VarTable,原靠 Deref coercion)。残余面(本 PR 不动,请队长立案/派工)
载体与共享 helper 已备,以下转换是机械活,但文件面被在飞车道
占用或签名无 env map:
(阶段 2 ④ Stage-2 ④ Phase 4: variable-attribute family onto Diag (Refs #2707) #2968 变量属性族面)。
进程 env 镜像已由本 PR 的盖戳维护,待签名线程化时一行转换)。
script_file:字段(std::env 同上)。