Fix "Readwise Syncs.md" JSON parse error when base folder is vault root#97
Merged
Merged
Conversation
When the plugin's base folder ("readwiseDir") is set to the vault root, the
exported markdown sync-log file ("Readwise Syncs.md") was misidentified as a
JSON book entry and run through JSON.parse, throwing:
SyntaxError: No number after minus sign in JSON at position 1
`processedFileName` is normalized with `normalizePath`, but the expected sync
path it was compared against was not. With a root base folder ("/" or ""), the
unnormalized side keeps a stray leading slash, the equality check fails, and the
plain-markdown sync file (which commonly starts with "- ") falls into the JSON
branch.
Normalize both sides of the comparison via a small `readwiseSyncFilePath`
helper, and add a regression test covering root, default, and nested base
folders.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes the Obsidian plugin error reported in DevHelp:
Highlights export fine, but the sync notification file fails to write.
Root cause
In
downloadExport(src/main.ts), each export ZIP entry is classified as either a JSON document file (→JSON.parse) or the special plain-markdown sync-log fileReadwise Syncs.md(→ used verbatim). The classification compares the normalizedprocessedFileNameagainst an un-normalized expected path:processedFileNameis built withnormalizePath(...), which strips leading slashes. When the user's base folder (readwiseDir) is the vault root ("/"or""), the right-hand side keeps a stray leading slash ("/Readwise Syncs.md") whileprocessedFileNamebecomes"Readwise Syncs.md". They no longer match, so the markdown sync file falls into theelsebranch and is fed toJSON.parse. Because the rendered notification commonly begins with-(e.g.- [[2026-05-28]] ...), V8 throwsNo number after minus sign in JSON at position 1.Per-document files are unaffected because they are genuine
.jsonentries — which is why highlights export fine while only the sync notification errors.Fix
Normalize both sides of the comparison via a small pure helper
readwiseSyncFilePath(readwiseDir, normalizePath)insrc/paths.ts, and use it inmain.ts. No behavior change for the defaultReadwisebase folder or nested folders; the root-folder case is now correctly recognized.Reproduction (exact user error)
A standalone repro of Obsidian's
normalizePath+ the original comparison reproduces the user's error verbatim and confirms the fix:Test plan
npm test— full suite passes (10/10), including newtests/paths.test.jscovering root, default, and nested base foldersnpm run build— production rollup bundle builds cleanReadwise Syncs.mdis written without error🤖 Generated with Claude Code