Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(api): point postgres password errors at rexctl doctor

Hampusc7afa4f81216
diff --git a/fluxer_api/pkgs/postgres/src/Client.ts b/fluxer_api/pkgs/postgres/src/Client.ts
index 16169fed8..66db8880f 100644
--- a/fluxer_api/pkgs/postgres/src/Client.ts
+++ b/fluxer_api/pkgs/postgres/src/Client.ts
@@ -5,6 +5,8 @@ import type {Pool, PoolClient, PoolConfig, QueryResult, QueryResultRow} from 'pg
import pg from 'pg';
const MAX_DIAGNOSTIC_FIELD_LENGTH = 128;
+const INVALID_PASSWORD_CODE = '28P01';
+const PASSWORD_MISMATCH_DOCS = 'https://docs.fluxer.app/operator/rexctl/#rexctl-doctor';
interface PostgresConnectionDiagnostic {
phase: 'idle' | 'checked_out';
@@ -93,6 +95,14 @@ function connectionDiagnostic(
};
}
+function explainConnectError(error: unknown): unknown {
+ if (!(error instanceof Error) || !('code' in error) || error.code !== INVALID_PASSWORD_CODE) return error;
+ return new Error(
+ `${error.message}. The password the API was given differs from the one stored in the existing Postgres data. Postgres sets that password only when its data volume is first created, so changing POSTGRES_PASSWORD later does not change it. Put the old password back, or run rexctl doctor --fix to set the new one inside the database: ${PASSWORD_MISMATCH_DOCS}`,
+ {cause: error},
+ );
+}
+
function reportConnectionError(diagnostic: PostgresConnectionDiagnostic): void {
console.error('Postgres connection error', diagnostic);
}
@@ -159,7 +169,7 @@ class PostgresClient implements IPostgresClient {
} catch (cleanupError) {
throw new AggregateError([error, cleanupError], 'Postgres connection and pool cleanup failed');
}
- throw error;
+ throw explainConnectError(error);
}
this.pool = pool;
}