Skip to content

fix: create sqlite db parent directory before opening#157

Merged
benvinegar merged 1 commit into
modem-dev:mainfrom
NikiforovAll:fix/sqlite-mkdir-parent
Jun 26, 2026
Merged

fix: create sqlite db parent directory before opening#157
benvinegar merged 1 commit into
modem-dev:mainfrom
NikiforovAll:fix/sqlite-mkdir-parent

Conversation

@NikiforovAll

Copy link
Copy Markdown
Contributor

Problem

npx sideshow@0.8.0 serve crashes on first run:

Error: unable to open database file
    at createSqliteStorage (.../server/sqliteStorage.js)
  code: 'ERR_SQLITE_ERROR', errcode: 14, errstr: 'unable to open database file'

node:sqlite's DatabaseSync does not create missing parent directories. The default db path resolves to <package>/data/sideshow.db, but the package ships no data/ folder — so the directory never exists on a fresh install and every default-path startup fails. It reproduces regardless of port or working directory; the only workaround today is setting SIDESHOW_DB to a path whose directory already exists.

Proposal

In createSqliteStorage, mkdirSync(dirname(path), { recursive: true }) before opening the database, guarded by the existing path !== ":memory:" check so the in-memory contract suite is untouched.

Impact

  • sideshow serve works out of the box on first run with no SIDESHOW_DB override.
  • A user-supplied SIDESHOW_DB pointing into a not-yet-created directory now works too.
  • No behavior change for :memory: or existing directories.

Verified: server boots against a nested non-existent db path and creates it; existing test/sqlStore.test.ts suite passes (30/30).

@NikiforovAll NikiforovAll force-pushed the fix/sqlite-mkdir-parent branch from 095de90 to 45c9407 Compare June 26, 2026 10:31
node:sqlite does not create missing parent directories and fails with
"unable to open database file". The default db path resolves under the
package dir, which ships no data/ folder, so sideshow serve crashed on
first run. Create the parent dir before opening the database.
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.

2 participants