Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mcclure opened this issue Apr 21, 2024 · 1 comment
Open

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

mcclure opened this issue Apr 21, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@mcclure
Copy link

mcclure commented Apr 21, 2024

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

  • Operating system: Ubuntu 20.04.6 LTS
  • Node version: v20.12.2
@mcclure mcclure added the bug Something isn't working label Apr 21, 2024
@bnewbold
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants