fix(cli): fail cleanly when a DB-requiring command has no backend - #729
Open
syf2211 wants to merge 3 commits into
Open
fix(cli): fail cleanly when a DB-requiring command has no backend#729syf2211 wants to merge 3 commits into
syf2211 wants to merge 3 commits into
Conversation
Detect --help in remaining Click args during TjGroup/TjCommand invoke and set a context flag so the root callback skips open_db(). Fixes nested invocations like `tj optimize downsize --help` failing with a database-lock error while tj serve is running. Fixes Metabuilder-Labs#580.
Add a shared guard in TjCommand.invoke that raises ClickException when db is None on DB-requiring leaf commands (Metabuilder-Labs#727). Wire requires_db through cli/main.py and reuse db_required_message in cmd_optimize. Includes regression tests for the loop annotate false-positive --help path and unit coverage for the guard.
Contributor
|
| Filename | Overview |
|---|---|
| tokenjam/cli/tj_status.py | Adds shared database-requirement metadata, missing-backend validation, and help-token detection to the central command class. |
| tokenjam/cli/main.py | Records whether the selected top-level command requires a database and skips database opening on the nested-help path. |
| tokenjam/cli/cmd_optimize.py | Delegates missing-backend handling to the shared guard and reuses the centralized error message. |
| tests/unit/test_tj_db_guard.py | Verifies shared error formatting, leaf-command enforcement, and group-command exemption. |
| tests/integration/test_cli.py | Covers nested help without a database probe and clean failure when a database-requiring leaf executes without a backend. |
Reviews (1): Last reviewed commit: "fix(cli): fail cleanly when a DB-requiri..." | Re-trigger Greptile
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.
Summary
Add a shared guard in
TjCommand.invokethat raises aClickExceptionwhen a DB-requiring leaf command runs withctx.obj["db"] is None, instead of crashing with anAttributeErrortraceback.Motivation
Issue #727: commands that skip
open_db()(including the--helpskip path from #726) but still execute can reach DB-touching code withdb=None.cmd_optimizealready had a hand-rolled message; other commands likeloop annotatedid not.Changes
db_required_message()and_ensure_db_available()toTjCommand(leaf commands only; groups skip the guard)ctx.obj["requires_db"]incli/main.py(Falseforno_db_commands,Trueotherwise)db is Nonecheck fromcmd_optimize; reuse the shared message for the ApiBackend pathTests
All passed locally.
Notes
--helpDB skip from fix(cli): skip DB probe when nested subcommand requests --help #726 (fix/group-subcommand-help-no-db). If fix(cli): skip DB probe when nested subcommand requests --help #726 merges first, this branch can be rebased to a single commit on top ofmain.--helptokens consumed as option values) is separate.Fixes #727