awk: `-f missing-file` and `--source` panic

未关闭 适合新手
#171 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@VanshajPoonia 已经在做这个了。

开始于 2026年11月18日。

  • #188 来自 @VanshajPoonia —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
80/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
cli

调研方向

从 parser/src/lib.rs:1037 中对 -f 的处理,以及 src/main.rs:51 中对 --source 的处理开始,issue 在这两处报告了 panic。为缺少程序文件和单独使用 --source 添加或使用列出的回归测试,然后确认前者报告错误且不包含“panicked”,后者输出 from source 并成功退出。

由索引模型根据 Issue 内容生成。

描述

bug crash gnu-compat good first issue

Two ways of giving the program text crash instead of running or reporting an
error:

  • -f with a file that cannot be opened panics on unwrap();
  • --source TEXT (-e) without -f panics because the code looks for the
    positional program argument.

Reproduction

Rust (incorrect)

$ ./target/release/awk -f missing.awk
thread 'main' panicked at parser/src/lib.rs:1037:38:
called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }
# Exit code: 2

$ ./target/release/awk --source 'BEGIN { print 1 }'
thread 'main' panicked at src/main.rs:51:43:
called `Option::unwrap()` on a `None` value

GNU (correct)

$ gawk -f missing.awk
gawk: fatal: cannot open source file `missing.awk' for reading: No such file or directory
# Exit code: 2

$ gawk --source 'BEGIN { print 1 }'
1

Test

#[test]
fn missing_program_file_is_an_error() {
    ucmd()
        .args(&["-f", "does-not-exist.awk"])
        .fails_with_code(2)
        .stderr_contains("does-not-exist.awk")
        .stderr_does_not_contain("panicked");
}

#[test]
fn source_option_alone() {
    ucmd()
        .args(&["--source", "BEGIN { print \"from source\" }"])
        .succeeds()
        .stdout_only("from source\n");
}

Exposed by the GNU awk test suite: sourcesplit, space, incdupe2, incdupe3,
incdupe4, incdupe7.

主要语言
Rust
星标
31
派生
13
平均合并
23 小时 42 分钟
30 天内合并 PR
29

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

uutils/awk 的其他 Issue

查看 uutils/awk 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。