#359·grex

CLI panics on empty input and on invalid UTF-8 input from stdin

Author: MathjkCreated Sep 29, 2026Updated Sep 29, 2026

Description

The grex CLI panics in two edge cases when reading input:

1. Empty input

Running grex - with empty stdin (e.g. grex - < /dev/null, or grex - < nul on Windows) or grex --file empty.txt with an empty file panics:

thread 'main' panicked at src/builder.rs:48:13:
No test cases have been provided for regular expression generation

This panic is reachable on the unmodified upstream source via the stock CLI: RegExpBuilder::from documents that it panics on empty test cases, and handle_input in src/main.rs passes the collected test cases to it without checking for emptiness first.

(For the record: issue #310 reported this same panic but was closed because the reporter had modified the source code. This reproduction is on a clean build of main, currently 99cc347, so the bug is real regardless of that report's circumstances.)

2. Invalid UTF-8 data on stdin

Piping non-UTF-8 bytes to grex - panics:

thread 'main' panicked at src/main.rs:304:38:
called `Result::unwrap()` on an `Err` value: Error { kind: InvalidData, message: "stream did not contain valid UTF-8" }

The same bytes supplied via grex --file <file> already produce a clean error message instead:

error: the specified file's encoding is not valid UTF-8

so the stdin code path is inconsistent with the file code path.

Expected behavior

Both cases should print a proper error message to stderr and exit with a non-zero status instead of panicking.

Environment

Reproduced deterministically on Windows 11 (x86_64-pc-windows-gnu build) and on Linux, using grex built from main @ 99cc347 with Rust stable.