Skip to content

Skip invalid stored profiles and chords instead of failing the load - #153

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/invalid-profile-entries-125
Sep 29, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/invalid-profile-entries-125

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #125

Problem

JsonKeybindingRepository.LoadAllProfilesInternalAsync caught only JsonException. A well-formed profiles.json that holds a chord with no notes, a blank note, or a profile with a blank id or name threw ArgumentException from the model constructors. KeybindingManager.InitializeAsync failed, and so did SaveAsync, because saving reloads the file first. A syntactically corrupt file was handled without error.

Change

  • Each profile and each chord is now converted on its own (ToProfile). An ArgumentException skips only the entry that caused it, so the rest of the file still loads.
  • Each skipped entry is written to Debug.WriteLine with the id and the reason, following AsyncBatchHelper. The doc comment notes that a later save does not write skipped entries back.
  • A null profile entry or a null notes array is treated as invalid and skipped, so it no longer causes a NullReferenceException.

Tests

InvalidStoredProfileEntryTests covers:

  • a corrupt file, which the repository had no test for yet
  • a chord with no notes (the JSON from the issue)
  • a blank note
  • a profile with a blank id or name
  • a save after entries were skipped keeps the valid profiles and bindings

With the fix reverted, 4 of the new tests fail. The corrupt-file test passes either way, because that path already worked. With the fix, the whole suite passes: 133 of 133.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WAdbE4VMmkBh1tzMGpC9Wy


Generated by Claude Code

…patch]

A well-formed profiles.json with an empty chord, a blank note, or a blank
profile id or name threw ArgumentException out of LoadAllProfilesAsync, so
KeybindingManager.InitializeAsync and SaveAsync failed while a syntactically
corrupt file was tolerated. Convert each profile and chord on its own, skip
the invalid ones, and write a debug line naming each skipped entry.

Fixes #125

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

Copy link
Copy Markdown

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 chord entry in profiles.json makes KeybindingManager.InitializeAsync throw, although a syntactically corrupt file is tolerated

2 participants