mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
fix(sqllab): Invalid SQL Error breaks SQL Lab (#33164)
This commit is contained in:
committed by
Michael S. Molina
parent
7c46374202
commit
f4ea15e477
@@ -43,6 +43,21 @@ const defaultProps = {
|
||||
subtitle: 'Test subtitle',
|
||||
};
|
||||
|
||||
const missingExtraProps = {
|
||||
...defaultProps,
|
||||
error: {
|
||||
error_type: ErrorTypeEnum.INVALID_SQL_ERROR,
|
||||
message: 'SQLStatement should have exactly one statement',
|
||||
level: 'error' as ErrorLevel,
|
||||
extra: {
|
||||
sql: null,
|
||||
line: null,
|
||||
column: null,
|
||||
engine: null,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const renderComponent = (overrides = {}) =>
|
||||
render(
|
||||
<ThemeProvider theme={supersetTheme}>
|
||||
@@ -60,6 +75,12 @@ describe('InvalidSQLErrorMessage', () => {
|
||||
expect(getByText('SELECT * FFROM table')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders the error message with the empty extra properties', () => {
|
||||
const { getByText } = renderComponent(missingExtraProps);
|
||||
expect(getByText('Unable to parse SQL')).toBeInTheDocument();
|
||||
expect(getByText(missingExtraProps.error.message)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('displays the SQL error line and column indicator', () => {
|
||||
const { getByText, container } = renderComponent();
|
||||
|
||||
|
||||
@@ -36,20 +36,22 @@ function InvalidSQLErrorMessage({
|
||||
source,
|
||||
subtitle,
|
||||
}: ErrorMessageComponentProps<SupersetParseErrorExtra>) {
|
||||
const { extra, level } = error;
|
||||
const { extra, level, message } = error;
|
||||
|
||||
const { sql, line, column } = extra;
|
||||
const lines = sql.split('\n');
|
||||
const lines = sql?.split('\n');
|
||||
let errorLine;
|
||||
if (line !== null) errorLine = lines[line - 1];
|
||||
else if (lines.length > 0) {
|
||||
if (line !== null && Number.isInteger(line)) errorLine = lines[line - 1];
|
||||
else if (lines?.length > 0) {
|
||||
errorLine = lines[0];
|
||||
}
|
||||
const body = errorLine && (
|
||||
const body = errorLine ? (
|
||||
<>
|
||||
<pre>{errorLine}</pre>
|
||||
{column !== null && <pre>{' '.repeat(column - 1)}^</pre>}
|
||||
</>
|
||||
) : (
|
||||
message
|
||||
);
|
||||
return (
|
||||
<ErrorAlert
|
||||
|
||||
Reference in New Issue
Block a user