ChordsOverWordsParser fails with TypeError on specific valid-looking inputs
Hello, and thank you for creating and maintaining the chordsheetjs library! It's a very powerful tool.
I am reporting a persistent issue I'm encountering with the ChordsOverWordsParser. It seems to fail with a TypeError on certain "chords-over-words" text inputs, while successfully parsing others that are structurally very similar.
Environment
- Library Version: "chordsheetjs": "^12.3.0",
- Runtime: Next.js 14 Server Action : "next": "14.2.31",
- Language: TypeScript
Steps to Reproduce
The issue can be reproduced with a simple, isolated function call, independent of my application's framework.
- Code used for parsing:
import {
ChordProParser,
ChordsOverWordsParser,
TextFormatter,
ChordProFormatter,
} from 'chordsheetjs';
function textToChordPro(textContent: string): string {
try {
const parser = new ChordsOverWordsParser();
const song = parser.parse(textContent);
const formatter = new ChordProFormatter();
return formatter.format(song);
} catch (error) {
console.error("Failed to convert text to ChordPro:", error);
return `{start_of_chorus}\n${textContent}\n{end_of_chorus}`;
}
}
- Test Case 1 (Successful): This input text is parsed correctly without any issues.
const successfulText1 = `
F G Am G F
Renova-me senhor Jesus
F C G
Já não quero ser igual
`;
textToChordPro(successfulText1); // This works
---
const successfulText2 = `
Am G F
Renova-me senhor Jesus
C G
Já não quero ser igual
`;
textToChordPro(successfulText2); // This works
- Test Case 2 (Fails): This input text, which appears to follow the same "chords-over-words" pattern, consistently fails.
const failingText1 = `
C G Am
Um menino nasceu
C G Am
Como um filho se nos deu
C
Ele é o próprio Deus
G Am
E vive em mim
`;
textToChordPro(failingText1); // This fails
---
const failingText2 = `
C G Am
Um menino nasceu
G Am
Como um filho se nos deu
C
Ele é o próprio Deus
Am
E vive em mim
`;
textToChordPro(failingText2); // This fails
Expected Behavior
I expect parser.parse(failingText) to succeed and return a valid chordpro object, just as it does for successfulText. The structure of both inputs seems to conform to the "chords-over-words" format.
Actual Behavior The parser.parse(failingText) call throws the following error:
TypeError: Cannot read properties of undefined (reading 'toLowerCase')
at Key.getNoteForNumber (...)
at Key.get note (...)
at Key.toString (...)
at Chord.toString (...)
at ChordSheetSerializer.parseChordLyricsPair (...)
...
Analysis and Debugging Attempts I have made several attempts to debug this, ruling out common issues:
- Non-Standard Whitespace: My first hypothesis was that hidden characters (like non-breaking spaces, \u00A0) were causing the issue. This was disproven when the error persisted even after I manually typed the entire failing text into the code, ensuring only standard spaces were used.
- Indentation and Alignment: My next hypothesis was that the parser was struggling with the leading whitespace on some lyric lines. I created a pre-processing function to normalize the indentation of the entire text block. This also did not solve the issue.
Given that the error persists even with a hardcoded string and after applying the documented solutions, I believe this might be a bug or a limitation in the parser's logic for handling certain valid chord/lyric alignments.
Is this a known issue, or is there a specific structural rule in the failingText that I am overlooking which makes it invalid?
Thank you for your time and for this great library. I'm happy to provide any more information needed.