Skip to content

fix(sqlite): accept a drive-letter path - #148

Open
PerryLink wants to merge 1 commit into
cordiverse:mainfrom
PerryLink:fix/sqlite-drive-letter-path
Open

PerryLink wants to merge 1 commit into
cordiverse:mainfrom
PerryLink:fix/sqlite-drive-letter-path

Conversation

@PerryLink

@PerryLink PerryLink commented Oct 18, 2026 •

Copy link
Copy Markdown

SQLiteDriver.start() at packages/sqlite/src/index.ts:166 parses config.path as a URL:

this.path = fileURLToPath(new URL(this.path, this.ctx.baseUrl))

path is documented as a filesystem path (z.string().role('path'), locale path: Database path.), but on Windows new URL('C:\\data\\koishi.db', base) reads C: as a URL scheme, and fileURLToPath throws TypeError: The URL must be of scheme file. An absolute path — accepted by resolve() before the migration — therefore cannot start the driver on Windows.

This is a regression from the v4 migration. origin/v3 resolved it as a filesystem path:

this.path = resolve(this.ctx.baseDir, this.path)

Commit 6bb2963 ("test: fix tests") replaced that line with the URL form and, in the same commit, changed the sqlite test from join(__dirname, 'test.db') to new URL('test.db', import.meta.url).href. The test was adapted to the new code, so the break was not caught.

The same idiom was fixed twice recently in cordiverse/cordis by the same maintainer: packages/include/src/index.ts (merged cordiverse/cordis#200) and packages/hmr/src/index.ts (merged cordiverse/cordis#208), both with the comment "new URL() would read its C: as a URL scheme, which fileURLToPath rejects". This patch applies the same conversion (via pathToFileURL) to the sqlite driver. Relative paths, file: URLs, POSIX-absolute paths and UNC paths still go through new URL() unchanged.

The test case is in the existing packages/sqlite/tests/index.spec.ts, so the package keeps running as a single vitest worker. It asserts the resolved path, is gated to Windows, and a control case covers relative paths. On an unmodified main the new case fails with the TypeError above; with the patch the package suite is 269 passed (267 + 2). Locally the shared performance beforeAll needs more than vitest's default 10 s hook timeout, on main as well as with this patch.

Relative paths containing # or ? are also truncated by new URL(); that is a separate issue and is not changed here.

`config.path` is documented as a filesystem path, but `start()` parsed it as
a URL. On Windows `new URL('C:\\data\\koishi.db', base)` reads `C:` as a URL
scheme and `fileURLToPath` throws `ERR_INVALID_URL_SCHEME`.

Convert a drive-letter path with `pathToFileURL`, the same way `include` and
`hmr` now do in `cordis`. Relative, POSIX-absolute, UNC and `file:` URL forms
are unchanged.

Regression: 6bb2963 replaced `resolve(this.ctx.baseDir, ...)` with the URL form
and rewrote the sqlite test to pass a `file:` URL in the same commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant