Skip to content

ParsePhrase("") throws "Phrase must contain at least one chord (Parameter 'sequence')" from its own empty-input guard #128

Description

@matt-edmondson

What's wrong

Keybinding/Services/KeybindingService.cs:178-183:

public Phrase ParsePhrase(string phraseString)
{
    if (string.IsNullOrWhiteSpace(phraseString))
    {
        return new Phrase([]);
    }

The Phrase constructor (MusicalTypes.cs:~318) rejects an empty sequence, so this branch can never return. Every call with null, "" or whitespace throws:

ArgumentException: Phrase must contain at least one chord (Parameter 'sequence')
   at Phrase..ctor
   at KeybindingService.ParsePhrase  KeybindingService.cs:182

Why it matters

The guard was clearly written to handle empty input in a controlled way, but the exception it produces names a parameter (sequence) that the caller never passed. A settings UI that parses a user's cleared keybinding field gets a confusing error that points inside the library. ParseChord validates its argument and throws with nameof(chordString), so the two parse methods behave differently.

Suggested fix

Pick one contract and implement it:

  • Throw new ArgumentException("Phrase string cannot be empty.", nameof(phraseString)), as ParseChord does. This is the minimal fix and doesn't change the API.
  • Or change the method to return Phrase? (or add TryParsePhrase) and return null for empty input.

Acceptance: ParsePhrase("") no longer throws from Phrase..ctor, and a test pins the chosen behaviour.

Activity

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions