Fix: GetNotes nil pointer crash due to NotebookLM API change #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: GetNotes API Response Parsing
Summary
The
nlm notescommand crashes with a nil pointer dereference when listing notes from a NotebookLM notebook. This PR fixes the crash and restores full functionality by implementing correct parsing of the API response, including extraction of note content.This issue seems to have been caused by the (undocumented) NotebookLM API changing the schema of the data returned by this function. The default unmarshaling couldn't parse the response, and so the nil pointer caused a full program crash. This fix adds a schema to the data (instead of inline assignment) to place the notes content in.
The note's content was also being discarded in the response. See other PR for possible extension to make use of it.
Issue
When running
nlm notes <notebook-id>, the command panics:Root Cause
The NotebookLM API returns note data in a custom nested array format that differs from the expected protobuf structure. The
beprotojsonunmarshaller was unable to correctly parse this format, resulting in:note.GetMetadata()returningnilnote.Titlebeing empty (populated from wrong field position)note.Contentnot being extracted at allAPI Response Structure
The API returns notes in this nested array structure:
The protobuf
Sourcemessage expectsTitleat field 2, but the API places it at position 4 of the nested details array. Content is at position 1.Changes
1.
gen/notebooklm/v1alpha1/notes_response.pb.go- API Structure DocumentationCreated new file documenting the expected API message types with proper position-to-field mappings:
NoteEntry- Outer array[source_id, details]NoteDetails- Inner array[id, content, metadata, null, title]NoteTimestampMetadata- Metadata[type, id, timestamp]TimestampPair- Timestamp[seconds, nanos]This serves as documentation for the API structure and could be extended for
beprotojsoncompatibility in the future.2.
gen/notebooklm/v1alpha1/notebooklm.pb.go- Content fieldAdded
Contentfield to theSourcestruct to store note body text:3.
gen/service/LabsTailwindOrchestrationService_client.go- Refactored parserRefactored
GetNoteswith:parseNoteEntryhelper function for cleaner, maintainable codebeprotojson.Unmarshalif API format changes4.
cmd/nlm/main.go- Nil guards inlistNotesAdded defensive nil checks when accessing note metadata to prevent crashes:
Also improved output formatting:
SourceIdwrapperTesting
Before Fix
After Fix
Notes are correctly displayed with titles from the right API position, timestamps parsed correctly, and draft notes show "(untitled)" with "unknown" timestamp.
Files Changed
gen/notebooklm/v1alpha1/notes_response.pb.gogen/notebooklm/v1alpha1/notebooklm.pb.goContentfield toSourcegen/service/LabsTailwindOrchestrationService_client.goparseNoteEntryhelper, content extractioncmd/nlm/main.golistNotesNotes
beprotojson.Unmarshalin case the API format changesSource.Contentfor downstream use (see proceeding PR)Related