hrw4u: no non-zero exit status on errors unless --stop-on-error is given
- Dominant language
- C++
- Stars
- 2k
- Forks
- 874
- Avg merge
- 6d 15h
- Merged PRs (30d)
- 46
Description
While reviewing #13204, we realized that `hrw4u` generally doesn't exit with a status code on errors, unless `--stop-on-error` is given. This applies to `u4wrh` as well.
In the default error-collecting mode, every input error — syntax *and* semantic — is reported on stderr, partial output still goes to stdout, and the process exits 0:
```
$ uv run ./scripts/hrw4u /tmp/foo.hrw4u
cond %{TXN_CLOSE_HOOK} [AND]
/tmp/foo.hrw4u:2:4: error: Unknown statement function: 'counters'
2 | counters("my.stat");
| ^
$ echo $?
0
```
`generate_output()` gates `sys.exit(1)` on `tree is None` (`tools/hrw4u/src/common.py:281`), which with `DefaultErrorStrategy` never happens — the parser recovers and returns a tree. Only `--stop-on-error` (bail strategy) and I/O failures exit non-zero.
So nothing can wrap either tool: CI steps, Makefiles, and `u4wrh in.hrw > out.hrw4u && hrw4u out.hrw4u` all see success on a failed compile. In bulk `in:out` mode a broken artifact is left on disk under a name that looks converted.
Suggested fix, keeping collect-all behavior (the flag should control when we stop, not whether the run failed): return a failure flag from `generate_output()`, OR it across all inputs at the three call sites (`common.py:366`, `:401`, `:429`), and `sys.exit(1)` at the end of `run_main()`. Also skip the `print` at `common.py:265` — or in `in:out` mode, don't write the output file at all — when errors were collected.
Contributor guide
Research direction
Start with tools/hrw4u/src/common.py, especially generate_output() at line 281, the print near line 265, and its call sites around lines 366, 401, and 429; then trace how run_main() handles completion. Run the documented uv command with an input containing a syntax or semantic error, and verify default mode reports the error, avoids misleading output artifacts, and exits non-zero while --stop-on-error still stops early.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100