Skip to content

awk: -f missing-file and --source panic #171

Open

Description

@sylvestre

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.

Activity

  1. added
    bug
    good first issue
    gnu-compat
    crash
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcrashgnu-compatgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions