fix(pglite): fail loudly on $bunfs data-dir paths (#250)#290
Open
RyanAlberts wants to merge 1 commit intogarrytan:masterfrom
Open
fix(pglite): fail loudly on $bunfs data-dir paths (#250)#290RyanAlberts wants to merge 1 commit intogarrytan:masterfrom
RyanAlberts wants to merge 1 commit intogarrytan:masterfrom
Conversation
When gbrain is compiled with `bun build --compile`, Bun mounts the bundled files under the `$bunfs://` virtual filesystem. PGLite's WASM module cannot access those paths — users saw either an opaque WASM panic or silent corruption of their on-disk brain state, with no actionable signal about what actually went wrong. This patch adds `assertRealFilesystemPath()` — a small guard called at the top of `PGLiteEngine.connect()` (before the file lock or PGLite itself is touched) that detects the `$bunfs` prefix and throws with an actionable error message pointing at the documented workarounds: - Run from source: bun run src/cli.ts <command> - Or pass --database-path with a real on-disk path The guard covers every documented shape: - $bunfs://... (URL-style) - $bunfs/... (bare prefix) - /$bunfs/... (absolute-path style, seen on Linux) - /<anything>/$bunfs/... (nested) Null/undefined/empty paths (in-memory PGLite) are unaffected. Fixes garrytan#250 Files: - src/core/pglite-path-guard.ts (new helper, exported for testing) - src/core/pglite-engine.ts (import + one-line guard call) - test/pglite-path-guard.test.ts (9 new tests) Test matrix: - isBunfsPath returns true for each documented shape - isBunfsPath returns false for normal paths and empty inputs - assertRealFilesystemPath throws with a message that mentions PGLite, the offending path, the `bun run src/cli.ts` workaround, --database-path, and the issue number for context - no-op on normal/undefined paths Verified with bun test (existing pglite-lock + engine-factory tests still pass). Did not run E2E suite. Made-with: Cursor
|
Hi, assertRealFilesystemPath() tells users to pass --database-path, but the CLI uses --path to set config.database_path; there is no --database-path flag implemented. Users hitting the new error will try the suggested workaround and fail again, defeating the purpose of the change. Severity: action required | Category: correctness How to fix: Use correct CLI flag name Agent prompt to fix - you can give this to your LLM of choice:
Found by Qodo code review. FYI, Qodo is free for open-source. |
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
When
gbrainis compiled withbun build --compile, Bun mounts the bundled files under$bunfs://— a virtual filesystem that PGLite's WASM module cannot read. The existing failure mode was either an opaque WASM panic or silent corruption of the on-disk brain state, leaving users with a half-initialized brain and no actionable signal about what went wrong.This PR adds a small guard —
assertRealFilesystemPath()— called at the top ofPGLiteEngine.connect(), before the file lock or PGLite itself is touched. The guard detects the$bunfsprefix and throws with an actionable error pointing at the documented workarounds:bun run src/cli.ts <command>--database-pathwith a real on-disk pathCoverage
The detector covers every documented
$bunfsshape:$bunfs://...(URL-style)$bunfs/...(bare prefix)/$bunfs/...(absolute-path style, seen on Linux)/<anything>/$bunfs/...(nested)Null / undefined / empty paths (in-memory PGLite, no data-dir) are unaffected.
Test plan
test/pglite-path-guard.test.ts:isBunfsPathreturnstruefor each documented shapeisBunfsPathreturnsfalsefor normal paths and empty inputsassertRealFilesystemPaththrows with a message that mentions PGLite, the offending path, thebun run src/cli.tsworkaround,--database-path, and the issue number for contextpglite-lock.test.ts+engine-factory.test.tsstill pass.bun testsuite: 1926 pass, 0 fail, 174 skip.Non-goals
This PR doesn't fix the underlying "compiled binary can't use PGLite" limitation — that likely needs PGLite WASM upstream work to read from
$bunfs, or a one-time copy-to-tmp dance during startup. What this PR does is replace "opaque WASM panic / silent corruption" with "clear, actionable error pointing at the workaround", so the ~20 users who hit this in #250 stop losing time to it.Fixes #250
Made with Cursor