mirror of https://github.com/apache/superset.git
feat: more error messages (#15409)
This commit is contained in:
parent
e713912fdf
commit
21d1fb55c6
|
@ -263,3 +263,11 @@ The database is currently running too many queries.
|
||||||
```
|
```
|
||||||
|
|
||||||
The database might be under heavy load, running too many queries. Please try again later, or contact an administrator for further assistance.
|
The database might be under heavy load, running too many queries. Please try again later, or contact an administrator for further assistance.
|
||||||
|
|
||||||
|
## Issue 1028
|
||||||
|
|
||||||
|
```
|
||||||
|
One or more parameters specified in the query are malformatted.
|
||||||
|
```
|
||||||
|
|
||||||
|
The query contains one or more malformed template parameters. Please check your query and confirm that all template parameters are surround by double braces, for example, "{{ ds }}". Then, try running your query again.
|
||||||
|
|
|
@ -57,6 +57,7 @@ export const ErrorTypeEnum = {
|
||||||
|
|
||||||
// Sqllab error
|
// Sqllab error
|
||||||
MISSING_TEMPLATE_PARAMS_ERROR: 'MISSING_TEMPLATE_PARAMS_ERROR',
|
MISSING_TEMPLATE_PARAMS_ERROR: 'MISSING_TEMPLATE_PARAMS_ERROR',
|
||||||
|
INVALID_TEMPLATE_PARAMS_ERROR: 'INVALID_TEMPLATE_PARAMS_ERROR',
|
||||||
RESULTS_BACKEND_NOT_CONFIGURED_ERROR: 'RESULTS_BACKEND_NOT_CONFIGURED_ERROR',
|
RESULTS_BACKEND_NOT_CONFIGURED_ERROR: 'RESULTS_BACKEND_NOT_CONFIGURED_ERROR',
|
||||||
DML_NOT_ALLOWED_ERROR: 'DML_NOT_ALLOWED_ERROR',
|
DML_NOT_ALLOWED_ERROR: 'DML_NOT_ALLOWED_ERROR',
|
||||||
INVALID_CTAS_QUERY_ERROR: 'INVALID_CTAS_QUERY_ERROR',
|
INVALID_CTAS_QUERY_ERROR: 'INVALID_CTAS_QUERY_ERROR',
|
||||||
|
|
|
@ -51,6 +51,10 @@ export default function setupErrorMessages() {
|
||||||
ErrorTypeEnum.MISSING_TEMPLATE_PARAMS_ERROR,
|
ErrorTypeEnum.MISSING_TEMPLATE_PARAMS_ERROR,
|
||||||
ParameterErrorMessage,
|
ParameterErrorMessage,
|
||||||
);
|
);
|
||||||
|
errorMessageComponentRegistry.registerValue(
|
||||||
|
ErrorTypeEnum.INVALID_TEMPLATE_PARAMS_ERROR,
|
||||||
|
ParameterErrorMessage,
|
||||||
|
);
|
||||||
errorMessageComponentRegistry.registerValue(
|
errorMessageComponentRegistry.registerValue(
|
||||||
ErrorTypeEnum.RESULTS_BACKEND_NOT_CONFIGURED_ERROR,
|
ErrorTypeEnum.RESULTS_BACKEND_NOT_CONFIGURED_ERROR,
|
||||||
DatabaseErrorMessage,
|
DatabaseErrorMessage,
|
||||||
|
|
|
@ -66,6 +66,7 @@ class SupersetErrorType(str, Enum):
|
||||||
|
|
||||||
# Sql Lab errors
|
# Sql Lab errors
|
||||||
MISSING_TEMPLATE_PARAMS_ERROR = "MISSING_TEMPLATE_PARAMS_ERROR"
|
MISSING_TEMPLATE_PARAMS_ERROR = "MISSING_TEMPLATE_PARAMS_ERROR"
|
||||||
|
INVALID_TEMPLATE_PARAMS_ERROR = "INVALID_TEMPLATE_PARAMS_ERROR"
|
||||||
RESULTS_BACKEND_NOT_CONFIGURED_ERROR = "RESULTS_BACKEND_NOT_CONFIGURED_ERROR"
|
RESULTS_BACKEND_NOT_CONFIGURED_ERROR = "RESULTS_BACKEND_NOT_CONFIGURED_ERROR"
|
||||||
DML_NOT_ALLOWED_ERROR = "DML_NOT_ALLOWED_ERROR"
|
DML_NOT_ALLOWED_ERROR = "DML_NOT_ALLOWED_ERROR"
|
||||||
INVALID_CTAS_QUERY_ERROR = "INVALID_CTAS_QUERY_ERROR"
|
INVALID_CTAS_QUERY_ERROR = "INVALID_CTAS_QUERY_ERROR"
|
||||||
|
@ -152,6 +153,15 @@ ERROR_TYPES_TO_ISSUE_CODES_MAPPING = {
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
SupersetErrorType.INVALID_TEMPLATE_PARAMS_ERROR: [
|
||||||
|
{
|
||||||
|
"code": 1028,
|
||||||
|
"message": _(
|
||||||
|
"Issue 1028 - One or more parameters specified in the query are "
|
||||||
|
"malformatted."
|
||||||
|
),
|
||||||
|
},
|
||||||
|
],
|
||||||
SupersetErrorType.RESULTS_BACKEND_NOT_CONFIGURED_ERROR: [
|
SupersetErrorType.RESULTS_BACKEND_NOT_CONFIGURED_ERROR: [
|
||||||
{
|
{
|
||||||
"code": 1021,
|
"code": 1021,
|
||||||
|
|
|
@ -48,6 +48,19 @@ class SupersetErrorException(SupersetException):
|
||||||
self.error = error
|
self.error = error
|
||||||
|
|
||||||
|
|
||||||
|
class SupersetGenericErrorException(SupersetErrorException):
|
||||||
|
"""Exceptions that are too generic to have their own type"""
|
||||||
|
|
||||||
|
def __init__(self, message: str) -> None:
|
||||||
|
super().__init__(
|
||||||
|
SupersetError(
|
||||||
|
message=message,
|
||||||
|
error_type=SupersetErrorType.GENERIC_BACKEND_ERROR,
|
||||||
|
level=ErrorLevel.ERROR,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SupersetErrorFromParamsException(SupersetErrorException):
|
class SupersetErrorFromParamsException(SupersetErrorException):
|
||||||
"""Exceptions that pass in parameters to construct a SupersetError"""
|
"""Exceptions that pass in parameters to construct a SupersetError"""
|
||||||
|
|
||||||
|
@ -97,11 +110,12 @@ class SupersetTemplateParamsErrorException(SupersetErrorFromParamsException):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
message: str,
|
message: str,
|
||||||
|
error: SupersetErrorType,
|
||||||
level: ErrorLevel = ErrorLevel.ERROR,
|
level: ErrorLevel = ErrorLevel.ERROR,
|
||||||
extra: Optional[Dict[str, Any]] = None,
|
extra: Optional[Dict[str, Any]] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(
|
super().__init__(
|
||||||
SupersetErrorType.MISSING_TEMPLATE_PARAMS_ERROR, message, level, extra,
|
error, message, level, extra,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,7 @@ from superset.exceptions import (
|
||||||
SupersetErrorsException,
|
SupersetErrorsException,
|
||||||
SupersetException,
|
SupersetException,
|
||||||
SupersetGenericDBErrorException,
|
SupersetGenericDBErrorException,
|
||||||
|
SupersetGenericErrorException,
|
||||||
SupersetSecurityException,
|
SupersetSecurityException,
|
||||||
SupersetTemplateParamsErrorException,
|
SupersetTemplateParamsErrorException,
|
||||||
SupersetTimeoutException,
|
SupersetTimeoutException,
|
||||||
|
@ -2540,7 +2541,12 @@ class Superset(BaseSupersetView): # pylint: disable=too-many-public-methods
|
||||||
|
|
||||||
mydb = session.query(Database).get(database_id)
|
mydb = session.query(Database).get(database_id)
|
||||||
if not mydb:
|
if not mydb:
|
||||||
return json_error_response("Database with id %i is missing.", database_id)
|
raise SupersetGenericErrorException(
|
||||||
|
_(
|
||||||
|
"The database referenced in this query was not found. Please "
|
||||||
|
"contact an administrator for further assistance or try again."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# Set tmp_schema_name for CTA
|
# Set tmp_schema_name for CTA
|
||||||
# TODO(bkyryliuk): consider parsing, splitting tmp_schema_name from
|
# TODO(bkyryliuk): consider parsing, splitting tmp_schema_name from
|
||||||
|
@ -2576,9 +2582,14 @@ class Superset(BaseSupersetView): # pylint: disable=too-many-public-methods
|
||||||
except SQLAlchemyError as ex:
|
except SQLAlchemyError as ex:
|
||||||
logger.error("Errors saving query details %s", str(ex), exc_info=True)
|
logger.error("Errors saving query details %s", str(ex), exc_info=True)
|
||||||
session.rollback()
|
session.rollback()
|
||||||
raise Exception(_("Query record was not created as expected."))
|
query_id = None
|
||||||
if not query_id:
|
if not query_id:
|
||||||
raise Exception(_("Query record was not created as expected."))
|
raise SupersetGenericErrorException(
|
||||||
|
_(
|
||||||
|
"The query record was not created as expected. Please "
|
||||||
|
"contact an administrator for further assistance or try again."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
logger.info("Triggering query_id: %i", query_id)
|
logger.info("Triggering query_id: %i", query_id)
|
||||||
|
|
||||||
|
@ -2600,7 +2611,10 @@ class Superset(BaseSupersetView): # pylint: disable=too-many-public-methods
|
||||||
query.status = QueryStatus.FAILED
|
query.status = QueryStatus.FAILED
|
||||||
session.commit()
|
session.commit()
|
||||||
raise SupersetTemplateParamsErrorException(
|
raise SupersetTemplateParamsErrorException(
|
||||||
utils.error_msg_from_exception(ex)
|
message=_(
|
||||||
|
'The query contains one or more malformed template parameters. Please check your query and confirm that all template parameters are surround by double braces, for example, "{{ ds }}". Then, try running your query again.'
|
||||||
|
),
|
||||||
|
error=SupersetErrorType.INVALID_TEMPLATE_PARAMS_ERROR,
|
||||||
)
|
)
|
||||||
|
|
||||||
if is_feature_enabled("ENABLE_TEMPLATE_PROCESSING"):
|
if is_feature_enabled("ENABLE_TEMPLATE_PROCESSING"):
|
||||||
|
@ -2619,6 +2633,7 @@ class Superset(BaseSupersetView): # pylint: disable=too-many-public-methods
|
||||||
)
|
)
|
||||||
+ " "
|
+ " "
|
||||||
+ PARAMETER_MISSING_ERR,
|
+ PARAMETER_MISSING_ERR,
|
||||||
|
error=SupersetErrorType.MISSING_TEMPLATE_PARAMS_ERROR,
|
||||||
extra={
|
extra={
|
||||||
"undefined_parameters": list(undefined_parameters),
|
"undefined_parameters": list(undefined_parameters),
|
||||||
"template_parameters": template_params,
|
"template_parameters": template_params,
|
||||||
|
|
Loading…
Reference in New Issue