Skip to content

Skip invalid stored commands instead of failing the load [patch] - #160

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/invalid-command-entries-133
Sep 30, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/invalid-command-entries-133

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #133

Problem

JsonKeybindingRepository.LoadCommandsAsync caught only JsonException. So a commands.json entry with a blank id or name (ArgumentException), or a null array element (NullReferenceException), made KeybindingManager.InitializeAsync throw. A file that isn't JSON at all loaded fine, as empty.

Change

Added ToCommand, the commands counterpart of the ToProfile helper from #125/#153. It converts each DTO on its own:

  • a null DTO is skipped
  • an entry that throws ArgumentException is dropped, with a Debug.WriteLine

The rest of the file loads. As with profiles, a skipped entry is not written back by a later save.

Tests

New InvalidStoredCommandEntryTests, alongside InvalidStoredProfileEntryTests:

  • The three repro inputs from the issue (blank name, missing id, null entry) each load file.save, and InitializeAsync does not throw. All three fail on main and pass with the fix.
  • A save after skipping bad entries keeps the valid one when reloaded. This also fails on main.
  • A corrupt commands.json still loads zero commands. This is a regression guard and passes both before and after.

The full suite passes locally: 139/139.

🤖 Generated with Claude Code

https://claude.ai/code/session_019UNSUUrn4o84JfkEVaD3xg


Generated by Claude Code

LoadCommandsAsync caught only JsonException, so a commands.json entry with a
blank id or name (ArgumentException) or a null element (NullReferenceException)
made KeybindingManager.InitializeAsync throw, although a file that is not JSON
at all loaded as empty. Each entry is now converted on its own, the same way
profiles.json entries are since #125, so a bad entry is dropped and the rest
load.

Fixes #133

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019UNSUUrn4o84JfkEVaD3xg
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit c640b74 into main Sep 30, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the fix/invalid-command-entries-133 branch September 30, 2026 04:00
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.

One invalid or null entry in commands.json makes KeybindingManager.InitializeAsync throw, although a syntactically corrupt commands.json is tolerated

2 participants