Skip to content

Issue #18 - [FEATURE] Add custom database error message configuration system #44

@rogelio-cmj

Description

@rogelio-cmj

Motivation

When database errors occur in Superset (e.g., permission denied, table not found, connection failures), users see raw database exception messages that can be cryptic, technical, and unhelpful.

A configurable system for transforming raw database errors into user-friendly messages would allow Superset administrators to customize error messages per database connection. This improves the user experience, reduces support burden, and allows organizations to provide context-specific guidance when database errors occur.

Current Behavior

When database errors occur in Superset (such as in SQL Lab or when loading charts), users see the raw exception message from the database engine. These messages are displayed as-is without any customization options.
Reproduction Steps:

  1. Navigate to SQL Lab in Superset
  2. Connect to any database (e.g., the "examples" database)
  3. Execute a query that will fail: SELECT * FROM non_existing_table
  4. Observe that the error message is the raw database exception with no customization options

Expected Behavior

Superset should provide a configuration system (CUSTOM_DATABASE_ERRORS) that allows administrators to define custom error messages for specific database errors. The system should:

  • Match database errors using regex patterns
  • Replace error messages with custom, user-friendly text
  • Support regex capture groups for dynamic message interpolation
  • Provide an option to hide the default "See more" button with technical issue codes
  • Work across all database error contexts (SQL Lab, chart loading, database validation)
  • Support per-database configuration (different messages for different database connections)

Acceptance Criteria:

  • A CUSTOM_DATABASE_ERRORS configuration can be defined in superset_config.py or a dedicated configuration file
  • Custom error messages are displayed instead of raw database exceptions when a regex pattern matches
  • The "See more" button with issue codes can be hidden when show_issue_info is set to False
  • The configuration supports regex capture groups for dynamic message content
  • The system works for errors in SQL Lab, chart execution, and database connection validation
  • All existing tests pass and new tests cover the custom error functionality

Steps To Test

  1. Add a custom error configuration to your superset_config.py:
import re
from flask_babel import gettext as __
from superset.errors import SupersetErrorType

CUSTOM_DATABASE_ERRORS = {
    "examples": {
        re.compile("no such table"): (
            __("The table you're trying to access doesn't exist"),
            SupersetErrorType.GENERIC_DB_ENGINE_ERROR,
            {
                "custom_doc_links": [
                    {
                        "url": "https://example.com/docs/tables",
                        "label": "View available tables"
                    }
                ],
                "show_issue_info": False,
            }
        )
    }
}
  1. Restart Superset to load the new configuration
  2. In SQL Lab, execute: SELECT * FROM non_existing_table
  3. Verify the custom error message appears instead of the raw database error
  4. Verify the "See more" button with issue codes is NOT displayed
  5. Test with show_issue_info: True and verify the "See more" button appears
  6. Test with a pattern using capture groups to verify dynamic message interpolation

Submission

Download https://cap.so/ to record your screen (use Studio mode). Export as an mp4, and drag and drop into an issue comment below.

Guide to submitting pull requests: https://hackmd.io/@timothy1ee/Hky8kV3hlx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions