fix(keys): fail with a clear message on a corrupt stored identity instead of a traceback - #6
Merged
Conversation
load_identity read config.json with json.loads(...)["agent_url"] and no guard, so a truncated/edited config or a missing agent_url surfaced as a raw JSONDecodeError/KeyError traceback on every command that loads the identity (sign, directory, doctor, serve, register). Wrap the key and config parsing and raise IdentityError (a ValueError subclass, so existing handlers keep working) with a 're-run wingfoot init' hint. main() catches it and prints a clean message with exit code 2. Add tests for the corrupt-config, missing-field, and CLI paths.
Merged
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
load_identityparsed the stored identity with no error handling:So if
~/.wingfoot/config.jsonis truncated, hand-edited, or missingagent_url, every command that loads the identity (sign,directory,doctor,serve,register) crashes with a raw traceback:Fix
load_identityand raiseIdentityError— aValueErrorsubclass (so any existingexcept ValueErrorkeeps working) — with an actionable message:config.json, a missingagent_url, and an unreadable/non-Ed25519 key file (the last previously raised a bareValueErrorthat also wasn't handled).cli.main()catchesIdentityErrorand prints a cleanwingfoot: ...message to stderr, returning exit code 2.Tests
Added tests/test_keys.py:
Nonewhen no identity existsconfig.json→IdentityErrorwith a re-run hintagent_url→IdentityErrorwingfoot directoryexit 2 with a clean stderr message (no traceback)Full suite: 50 passed (45 + 5 new).
Note: this touches
cli.py(themain()handler and thekeysimport) but in different regions than #4, so the two should merge cleanly regardless of order.