mirror of
https://github.com/apache/superset.git
synced 2026-04-23 10:04:45 +00:00
chore(sql_parse): Provide more meaningful SQLGlot errors (#27858)
This commit is contained in:
@@ -752,11 +752,21 @@ class ParsedQuery:
|
||||
statements = parse(self.stripped(), dialect=self._dialect)
|
||||
except SqlglotError as ex:
|
||||
logger.warning("Unable to parse SQL (%s): %s", self._dialect, self.sql)
|
||||
dialect = self._dialect or "generic"
|
||||
|
||||
message = (
|
||||
"Error parsing near '{highlight}' at line {line}:{col}".format( # pylint: disable=consider-using-f-string
|
||||
**ex.errors[0]
|
||||
)
|
||||
if isinstance(ex, ParseError)
|
||||
else str(ex)
|
||||
)
|
||||
|
||||
raise SupersetSecurityException(
|
||||
SupersetError(
|
||||
error_type=SupersetErrorType.QUERY_SECURITY_ACCESS_ERROR,
|
||||
message=__(f"Unable to parse SQL ({dialect}): {self.sql}"),
|
||||
message=__(
|
||||
f"You may have an error in your SQL statement. {message}"
|
||||
),
|
||||
level=ErrorLevel.ERROR,
|
||||
)
|
||||
) from ex
|
||||
|
||||
Reference in New Issue
Block a user