bluesky-social / atproto

Social networking technology created by Bluesky
Other
5.77k stars 406 forks source link

PDS: Error message on failure to open database is unhelpful #2433

Open mcclure opened 2 months ago

mcclure commented 2 months ago

Describe the bug

Say one boots the pds server, but it cannot open its files for writing. It will give this very unhelpful error message:

Started atproto personal data server.
/var2/www2/bsky/pds/service/node_modules/.pnpm/better-sqlite3@9.4.1/node_modules/better-sqlite3/lib/database.js:69
              [util.cppdb]: { value: new addon.Database(filename, filenameGiven, anonymous, readonly, fileMustExist, timeout, verbose || null, buffer || null) },
                                     ^
SqliteError: unable to open database file
    at new Database (/var2/www2/bsky/pds/service/node_modules/.pnpm/better-sqlite3@9.4.1/node_modules/better-sqlite3/lib/database.js:69:26)
    at Function.sqlite (/var2/www2/bsky/pds/service/node_modules/.pnpm/@atproto+pds@0.4.12/node_modules/@atproto/pds/src/db/db.ts:31:22)
    at getDb (/var2/www2/bsky/pds/service/node_modules/.pnpm/@atproto+pds@0.4.12/node_modules/@atproto/pds/src/did-cache/db/index.ts:16:19)
    at DidSqliteCache (/var2/www2/bsky/pds/service/node_modules/.pnpm/@atproto+pds@0.4.12/node_modules/@atproto/pds/src/did-cache/index.ts:17:20)
    at Function.fromConfig (/var2/www2/bsky/pds/service/node_modules/.pnpm/@atproto+pds@0.4.12/node_modules/@atproto/pds/src/context.ts:130:22)
    at Function.create (/var2/www2/bsky/pds/service/node_modules/.pnpm/@atproto+pds@0.4.12/node_modules/@atproto/pds/src/index.ts:65:34)
    at main (/var2/www2/bsky/pds/service/index.js:16:25)
    at Object.<anonymous> (/var2/www2/bsky/pds/service/index.js:72:1)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1427:10) {
  code: 'SQLITE_CANTOPEN'
}

The error message says it could not open the "database file". However, it does not give the path which it was unable to open. The pds server involves several database files, so without a path it is difficult for a user to act on this error message. I lost quite a bit of time trying to understand what it wanted me to do.

To Reproduce

I encountered the error while following these third-party instructions for running the pds server without docker. I was able to cause the error by creating the pds/service/data/blocks directory (within a checkout of the pds repository) but then setting the ownership/permissions of data and data/blocks such that the user that would be running the pds server could not read or write them.

Although this error would be less likely to organically occur when using docker as recommended, I believe you could still reproduce the error in docker by setting the file permissions on the data directory to something unreasonable such as 000.

Expected behavior

db.ts, in the static sqlite() function, when calling new SqliteDb(), should catch the SqliteError(code='SQLITE_CANTOPEN') and re-throw or otherwise log the error in a way that includes the current value of location in the error message.

Details

bnewbold commented 2 months ago

Thanks for filing! This is indeed an unhelpful message for folks not following the exact setup instructions.

For transparency, we probably won't implement this ourselves one-off until we do a larger iteration on the PDS setup/deploy experience. But we would review PRs for this if you or others are interested in contributing.