Skip to content

fix(keys): fail with a clear message on a corrupt stored identity instead of a traceback - #6

Merged
AmirF194 merged 1 commit into
AmirF194:mainfrom
ebarkhordar:fix/load-identity-corrupt
Jul 19, 2026
Merged

fix(keys): fail with a clear message on a corrupt stored identity instead of a traceback#6
AmirF194 merged 1 commit into
AmirF194:mainfrom
ebarkhordar:fix/load-identity-corrupt

Conversation

@ebarkhordar

Copy link
Copy Markdown
Contributor

Problem

load_identity parsed the stored identity with no error handling:

config = json.loads(config_path.read_text())
return Identity(private_key=private_key, agent_url=config["agent_url"])

So if ~/.wingfoot/config.json is truncated, hand-edited, or missing agent_url, every command that loads the identity (sign, directory, doctor, serve, register) crashes with a raw traceback:

$ wingfoot directory
Traceback (most recent call last):
  ...
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 18 (char 17)

Fix

  • Guard the key- and config-parsing in load_identity and raise IdentityError — a ValueError subclass (so any existing except ValueError keeps working) — with an actionable message:
    identity config ~/.wingfoot/config.json is corrupt or incomplete (...); re-run `wingfoot init`
    
    This covers a corrupt/truncated config.json, a missing agent_url, and an unreadable/non-Ed25519 key file (the last previously raised a bare ValueError that also wasn't handled).
  • cli.main() catches IdentityError and prints a clean wingfoot: ... message to stderr, returning exit code 2.

Tests

Added tests/test_keys.py:

  • save→load round-trip, and None when no identity exists
  • corrupt (truncated) config.jsonIdentityError with a re-run hint
  • valid JSON missing agent_urlIdentityError
  • CLI path: a corrupt identity makes wingfoot directory exit 2 with a clean stderr message (no traceback)

Full suite: 50 passed (45 + 5 new).


Note: this touches cli.py (the main() handler and the keys import) but in different regions than #4, so the two should merge cleanly regardless of order.

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.
@AmirF194
AmirF194 merged commit 13fdaf9 into AmirF194:main Jul 19, 2026
5 checks passed
@AmirF194 AmirF194 mentioned this pull request Jul 19, 2026
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.

2 participants