Skip to content

InitializeAsync throws ArgumentException when the stored active profile id is whitespace #167

Closed

Description

@matt-edmondson

What's wrong

KeybindingManager.InitializeAsync guards the stored active profile with IsNullOrEmpty (Keybinding/KeybindingManager.cs:103):

if (!string.IsNullOrEmpty(activeProfileId) && Profiles.ProfileExists(activeProfileId))

but ProfileManager.ProfileExists throws on whitespace (Keybinding/Services/ProfileManager.cs:128-131):

return string.IsNullOrWhiteSpace(profileId)
    ? throw new ArgumentException("Profile ID cannot be null or whitespace", nameof(profileId))

JsonKeybindingRepository.LoadActiveProfileAsync returns the stored id verbatim, so a whitespace id passes the first check and throws from the second.

Failure scenario

active-profile.json contains {"activeProfileId": " "}. It might have been hand-edited, or it might come from a custom IKeybindingRepository. InitializeAsync then throws ArgumentException: Profile ID cannot be null or whitespace. Commands and profiles have already been loaded at that point, so the manager is left half-initialized. A missing, unknown or corrupt active profile id loads without error. Only a blank one crashes.

This was missed alongside #125 and #133, which made invalid stored profiles, chords and commands get skipped instead of failing the load. The active-profile entry was not covered by those fixes.

Suggested fix / acceptance criteria

  • Use string.IsNullOrWhiteSpace at KeybindingManager.cs:103, or have LoadActiveProfileAsync return null for a blank id.
  • Add a test next to the existing invalid-stored-entry tests. It loads a whitespace active profile id and expects InitializeAsync to complete with no active profile set and no exception.

Activity

  1. matt-edmondson commented on Oct 5, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions