GitHub user dosubot[bot] added a comment to the discussion: Show friendly error when Superset unable to connect to backing database
<!-- Answer --> Superset already has a built-in mechanism for transforming raw database errors into user-friendly messages — it's the `custom_errors` dictionary in each database engine spec. For PostgreSQL specifically, patterns for connection failures (invalid password, host down, port closed) are already defined in `superset/db_engine_specs/postgres.py` [[1]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/db_engine_specs/postgres.py#L121-L176). Here's how the system works and how you can customize it: **How it works:** When a chart query fails, `BaseEngineSpec.extract_errors()` matches the raw error message against regex patterns in `custom_errors`. If a pattern matches, it returns a structured `SupersetError` with a sanitized, user-friendly message instead of the raw driver output [[2]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/db_engine_specs/base.py#L1252-L1278). **Why you might still see raw errors:** If the specific error string from your psycopg2 driver doesn't match any of the existing regex patterns, the system falls back to `GENERIC_DB_ENGINE_ERROR`, which may still expose raw details [[3]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/db_engine_specs/base.py#L1271-L1278). **To wrap connection errors in a friendlier message**, you can extend the PostgreSQL engine spec's `custom_errors` dictionary in `superset/db_engine_specs/postgres.py`: ```python # Add a pattern that catches the "password authentication failed" error CONNECTION_INVALID_PASSWORD_REGEX = re.compile( r'connection to server .+ failed: FATAL:\s+password authentication failed for user' ) # Then in the custom_errors dict: custom_errors = { CONNECTION_INVALID_PASSWORD_REGEX: ( __("Unable to connect to the database. Please contact your administrator."), SupersetErrorType.CONNECTION_INVALID_PASSWORD_ERROR, {"invalid": ["password"]}, ), # ... other patterns } ``` This approach lets you: - Hide host/port/user details from end users - Show a generic "network error" or "unable to connect" message - Still log the full error server-side for debugging If you want a broader catch-all for *any* connection failure (not just password errors), you could add a more general regex pattern that matches the `psycopg2.OperationalError` message format and maps it to a generic friendly message. Note that Superset also has password masking for SQLAlchemy URIs that appear in error metadata [[4]](https://github.com/apache/superset/pull/38229), but that's separate from the chart-facing error messages you're asking about. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).* --- Docs are dead. Just use [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-tagline&utm_term=apache%2Fsuperset). [](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-feedback&utm_term=apache%2Fsuperset&message_id=402d7f3a-7161-4447-aad0-c2bf406cc40d) [](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-ask-repo&utm_term=apache%2Fsuperset) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-share-team&utm_term=apache%2Fsuperset) GitHub link: https://github.com/apache/superset/discussions/40881#discussioncomment-17231094 ---- This is an automatically sent email for [email protected]. To unsubscribe, please send an email to: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
