fix(workflows): handle an unreadable run state in workflow status - #3999
Merged
Conversation
`workflow status <run_id>` and `workflow resume <run_id>` both call `RunState.load()`, and a prior fix aligned them on the FileNotFoundError and ValueError boundaries. `resume` also handles OSError; `status` never gained that handler. So an unreadable `state.json` -- wrong permissions, an I/O error, or a directory sitting where the file belongs -- escapes as a raw traceback with no output at all, while `resume` on the same run prints a clean `Error:` line and exits 1. `state_path.exists()` is True for a directory, so the existing guard passes and `open()` raises. Add the missing `except OSError` next to its siblings, using the same `_escape_markup` + `typer.Exit(1)` shape, and routing through `err` so the message lands on stderr under `--json` and the stdout JSON stream stays parseable. Two regression tests: the end-to-end CLI path (a directory in place of state.json) and the `--json` stderr-routing path. Both fail without the source change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Handles unreadable workflow run state files without leaking raw tracebacks.
Changes:
- Catches
OSErrorinworkflow status. - Routes JSON-mode errors to stderr.
- Adds CLI and stderr-routing regression tests.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/workflows/_commands.py |
Adds clean OSError handling. |
tests/test_workflows.py |
Covers unreadable state and JSON output. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced
Collaborator
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
workflow status <run_id>andworkflow resume <run_id>both load the same run state viaRunState.load(). A prior fix aligned the two on theFileNotFoundErrorandValueErrorboundaries, butresumealso handlesOSErrorandstatusnever gained that handler:So an unreadable
state.json— wrong permissions, an I/O error, or a directory sitting where the file belongs — escapesworkflow statusas a raw traceback, whileresumeon the very same run exits cleanly.state_path.exists()returns True for a directory, so the existing guard passes andopen()raises.Reproduction
With a run directory whose
state.jsonis a directory, on unmodifiedmain:statusprints nothing at all and dumps a traceback;resumeprints a clean error. Reproduced through the real Typer CLI, no mocking.Fix
Add the missing
except OSErrorbeside its siblings, using the same_escape_markup+typer.Exit(1)shape as the neighbouring handlers, and routing througherrso the message goes to stderr under--jsonand the stdout JSON stream stays parseable.Tests
Two regression tests in
TestWorkflowCliAlignment, next to the existingstatus/resumealignment tests:test_status_unreadable_run_state_exits_cleanly— end-to-end CLI, a directory in place ofstate.jsontest_status_json_unreadable_run_state_error_goes_to_stderr—--jsonstderr routing, mirroring the siblingValueErrortestBoth fail without the source change (verified by reverting
_commands.pyalone) and pass with it.tests/test_workflows.py: 898 passed, up from 896 on the same tree, with an unchanged set of 20 pre-existing failures — all Windows symlink tests that need elevation and fail identically on unmodifiedmain.🤖 Generated with Claude Code