fix(sqllab): duplicate error message (#31353)

This commit is contained in:
Beto Dealmeida 2024-12-09 12:31:00 -05:00 committed by GitHub
parent 3bfead66c4
commit fc45647440
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 34 deletions

View File

@ -30,7 +30,6 @@ import fetchMock from 'fetch-mock';
import ResultSet from 'src/SqlLab/components/ResultSet'; import ResultSet from 'src/SqlLab/components/ResultSet';
import { import {
cachedQuery, cachedQuery,
failedQueryWithErrorMessage,
failedQueryWithErrors, failedQueryWithErrors,
queries, queries,
runningQuery, runningQuery,
@ -41,6 +40,11 @@ import {
failedQueryWithFrontendTimeoutErrors, failedQueryWithFrontendTimeoutErrors,
} from 'src/SqlLab/fixtures'; } from 'src/SqlLab/fixtures';
jest.mock(
'src/components/ErrorMessage/ErrorMessageWithStackTrace',
() => () => <div data-test="error-message">Error</div>,
);
const mockedProps = { const mockedProps = {
cache: true, cache: true,
queryId: queries[0].id, queryId: queries[0].id,
@ -93,15 +97,6 @@ const cachedQueryState = {
}, },
}, },
}; };
const failedQueryWithErrorMessageState = {
...initialState,
sqlLab: {
...initialState.sqlLab,
queries: {
[failedQueryWithErrorMessage.id]: failedQueryWithErrorMessage,
},
},
};
const failedQueryWithErrorsState = { const failedQueryWithErrorsState = {
...initialState, ...initialState,
sqlLab: { sqlLab: {
@ -314,26 +309,17 @@ describe('ResultSet', () => {
expect(getByText('fetching')).toBeInTheDocument(); expect(getByText('fetching')).toBeInTheDocument();
}); });
test('should render a failed query with an error message', async () => {
await waitFor(() => {
setup(
{ ...mockedProps, queryId: failedQueryWithErrorMessage.id },
mockStore(failedQueryWithErrorMessageState),
);
});
expect(screen.getByText('Database error')).toBeInTheDocument();
expect(screen.getByText('Something went wrong')).toBeInTheDocument();
});
test('should render a failed query with an errors object', async () => { test('should render a failed query with an errors object', async () => {
const { errors } = failedQueryWithErrors;
await waitFor(() => { await waitFor(() => {
setup( setup(
{ ...mockedProps, queryId: failedQueryWithErrors.id }, { ...mockedProps, queryId: failedQueryWithErrors.id },
mockStore(failedQueryWithErrorsState), mockStore(failedQueryWithErrorsState),
); );
}); });
expect(screen.getByText('Database error')).toBeInTheDocument(); const errorMessages = screen.getAllByTestId('error-message');
expect(errorMessages).toHaveLength(errors.length);
}); });
test('should render a timeout error with a retrial button', async () => { test('should render a timeout error with a retrial button', async () => {

View File

@ -42,7 +42,6 @@ import {
css, css,
getNumberFormatter, getNumberFormatter,
getExtensionsRegistry, getExtensionsRegistry,
ErrorLevel,
ErrorTypeEnum, ErrorTypeEnum,
} from '@superset-ui/core'; } from '@superset-ui/core';
import ErrorMessageWithStackTrace from 'src/components/ErrorMessage/ErrorMessageWithStackTrace'; import ErrorMessageWithStackTrace from 'src/components/ErrorMessage/ErrorMessageWithStackTrace';
@ -559,16 +558,7 @@ const ResultSet = ({
} }
if (query.state === QueryState.Failed) { if (query.state === QueryState.Failed) {
const errors = []; const errors = [...(query.extra?.errors || []), ...(query.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 ( return (
<ResultlessStyles> <ResultlessStyles>

View File

@ -532,6 +532,12 @@ export const failedQueryWithErrors = {
level: 'error', level: 'error',
extra: null, extra: null,
}, },
{
message: 'Something else wrong',
error_type: 'TEST_ERROR',
level: 'error',
extra: null,
},
], ],
id: 'ryhMUZCGb', id: 'ryhMUZCGb',
progress: 0, progress: 0,