Repository navigation
fix(cli): fail check on database login errors and read ~/.pgpass - #839
Merged
Merged
Conversation
…ord file When a database is configured, `check` now connects up front and reports a failed connection or login as a `database/connection` error with a non-zero exit, instead of skipping the database-backed checks silently. `--disable-db` and `db.disableConnection` still check without a database; the config option was overridden by the CLI default before. Without a password from the configuration, the connection string, or PGPASSWORD, the password is looked up in PGPASSFILE or ~/.pgpass as libpq does, before falling back to the default `postgres`. Fixes #834
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.
checkno longer passes silently when the configured database can't be used, and it reads the password from~/.pgpass/PGPASSFILEthe way libpq clients do.Connection failures fail
checkWhen a database is configured (not disabled),
checkconnects and loads the schema before checking the files. If that fails, it reports adatabase/connectionerror, still runs the checks that don't need the database, and exits non-zero. This includes a connection that is still in backoff from an earlier failure in the daemon. The error is visible without a log level:This adds a
check_database_connectionworkspace method, which the daemon also serves. The connection outcome is returned as a result value, not an error, because workspace errors lose their type over JSON-RPC. The LSP doesn't call the new method, so its behaviour is unchanged: it backs off and keeps working without the database.The
DatabaseConnectionErrordiagnostic template didn't interpolate, sodblintprinted the literalDatabase error: {message}. That's fixed too.disableConnectionin the config file is honoured by the CLI--disable-dbwas declared asswitchwithfallback(Some(false)), so the CLI's partial configuration always carrieddisableConnection: falseand overrodetruefrom the config file. That was invisible while failures were silent; it would now failcheck. The flag now only sets the value when passed.Password file
With no password from the config,
--password, orPGPASSWORD, the password is looked up inPGPASSFILE, else~/.pgpass(%APPDATA%\postgresql\pgpass.confon Windows). If nothing matches, it falls back to the documented defaultpostgres. That fallback is the conservative choice: setups that rely on it keep working.sqlx 0.8 has pgpass support, but it isn't usable here:
PgConnectOptions::new()/ URL parsing. We called.host().port().username()after that, so it matched against the environment's defaults, and then we always overwrote the password.\:/\\in the password, it falls back to~/.pgpasswhenPGPASSFILEhas no match, and it checks permissions only on Linux.So
pgpass.rsports libpq'spasswordFromFile/pwdfMatchesString(REL_18_6). Like libpq, it ignores the file on Unix if group or others can access it, or if it isn't a regular file. Connection strings without a password use the same lookup, and keep sqlx's result when it finds nothing.Follow-ups, not changed here
--conn_timeout_secshas the samefallback(Some(10))pattern, so the CLI overridesconnTimeoutSecsfrom the config file.--use-server), file diagnostics fail with "Method not found". The client requestspgls/pull_diagnostics, but the server registerspgls/pull_file_diagnostics. This is already the case on main.pool timed out while waiting for an open connectionrather than the underlying error.Fixes #834