Skip to content

fix(tui): exit 1 when the results file is not written - #201

Closed
bfs2021 wants to merge 1 commit into
TMHSDigital:mainfrom
bfs2021:fix/tui-exit-code-output-error
Closed

bfs2021 wants to merge 1 commit into
TMHSDigital:mainfrom
bfs2021:fix/tui-exit-code-output-error

Conversation

@bfs2021

@bfs2021 bfs2021 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Problem

subenum -tui exits 0 when the results file could not be written, while the CLI exits 1 in the same situation (Fixes #155). Scripts that launch the TUI and check $? treat a truncated or missing results file as success.

Root cause

reportOutputErr recorded the failure only as a message in the scan view. exitCode consults scanView.failed(), which tracks scan errors alone, so an output-file error never reached the process exit code.

Fix

Track the failure on the model (outputErr) when reportOutputErr is called and return 1 from exitCode when it is set. This mirrors the CLI, where a file error outranks "no changes".

Testing

  • go test ./internal/tui/ passes. The new TestOutputFileFailureSetsExitCode drives a real finalizeOutput failure (a directory blocking the final rename), asserts exit code 1 and the on-screen message, and checks that a clean model still exits 0.
  • gofmt -l clean.

reportOutputErr only added a message to the view, so exitCode still
returned 0 after a failed write and scripts checking $? treated a
truncated or missing results file as success. Track the failure on the
model and fail the run, matching the CLI, where a file error outranks
everything else.
@TMHSDigital

Copy link
Copy Markdown
Owner

Thank you for this. The root-cause write-up was clear and accurate.

#155 was fixed on main in b79b6cd before this PR was reviewed, with the same change (an outputErr flag set by reportOutputErr and checked in exitCode; on main it lives on the scan view, so starting a new scan resets it). This branch now conflicts with main.

Your test is better than the one on main: it makes finalizeOutput really fail instead of injecting an error. I've taken TestOutputFileFailureSetsExitCode into main in 227e756, with you as co-author, plus a CHANGELOG entry. It passes against the code on main.

Closing this as superseded. Thanks again, and contributions are welcome on the other open issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: TUI exits 0 when the results file failed to write

2 participants