From a09880929482ef7ff93cd7bee124e56a9bb741b1 Mon Sep 17 00:00:00 2001 From: Beto Dealmeida Date: Fri, 4 Oct 2024 19:17:56 -0400 Subject: [PATCH] feat(SQL Lab): better SQL parsing error messages (#30501) --- .../src/SqlLab/components/ResultSet/index.tsx | 36 +++-- .../InvalidSQLErrorMessage.test.tsx | 126 ++++++++++++++++++ .../ErrorMessage/InvalidSQLErrorMessage.tsx | 62 +++++++++ .../src/setup/setupErrorMessages.ts | 5 + superset/exceptions.py | 2 +- superset/sql_lab.py | 9 +- 6 files changed, 226 insertions(+), 14 deletions(-) create mode 100644 superset-frontend/src/components/ErrorMessage/InvalidSQLErrorMessage.test.tsx create mode 100644 superset-frontend/src/components/ErrorMessage/InvalidSQLErrorMessage.tsx diff --git a/superset-frontend/src/SqlLab/components/ResultSet/index.tsx b/superset-frontend/src/SqlLab/components/ResultSet/index.tsx index 067a2c3b0958e..3e9c9db5c6d48 100644 --- a/superset-frontend/src/SqlLab/components/ResultSet/index.tsx +++ b/superset-frontend/src/SqlLab/components/ResultSet/index.tsx @@ -42,6 +42,7 @@ import { css, getNumberFormatter, getExtensionsRegistry, + ErrorLevel, ErrorTypeEnum, } from '@superset-ui/core'; import ErrorMessageWithStackTrace from 'src/components/ErrorMessage/ErrorMessageWithStackTrace'; @@ -540,18 +541,33 @@ const ResultSet = ({ } if (query.state === QueryState.Failed) { + const errors = []; + if (query.errorMessage) { + errors.push({ + error_type: ErrorTypeEnum.GENERIC_DB_ENGINE_ERROR, + extra: {}, + level: 'error' as ErrorLevel, + message: query.errorMessage, + }); + } + errors.push(...(query.extra?.errors || []), ...(query.errors || [])); + return ( - {query.errorMessage}} - copyText={query.errorMessage || undefined} - link={query.link} - source="sqllab" - /> - {(query?.extra?.errors?.[0] || query?.errors?.[0])?.error_type === - ErrorTypeEnum.FRONTEND_TIMEOUT_ERROR ? ( + {errors.map((error, index) => ( + {error.message}} + copyText={error.message || undefined} + link={query.link} + source="sqllab" + /> + ))} + {errors.some( + error => error?.error_type === ErrorTypeEnum.FRONTEND_TIMEOUT_ERROR, + ) ? (