Improve kql error message handling and avoid fetcihng twice (#54239)
This commit is contained in:
parent
d8f94b1792
commit
6cbfa8ee3e
|
@ -671,7 +671,9 @@ function discoverController(
|
|||
$scope.$watch('state.query', (newQuery, oldQuery) => {
|
||||
if (!_.isEqual(newQuery, oldQuery)) {
|
||||
const query = migrateLegacyQuery(newQuery);
|
||||
$scope.updateQueryAndFetch({ query });
|
||||
if (!_.isEqual(query, newQuery)) {
|
||||
$scope.updateQueryAndFetch({ query });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -817,6 +819,7 @@ function discoverController(
|
|||
title: i18n.translate('kbn.discover.errorLoadingData', {
|
||||
defaultMessage: 'Error loading data',
|
||||
}),
|
||||
toastMessage: error.shortMessage,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -41,7 +41,7 @@ const grammarRuleTranslations: Record<string, string> = {
|
|||
|
||||
interface KQLSyntaxErrorData extends Error {
|
||||
found: string;
|
||||
expected: KQLSyntaxErrorExpected[];
|
||||
expected: KQLSyntaxErrorExpected[] | null;
|
||||
location: any;
|
||||
}
|
||||
|
||||
|
@ -53,19 +53,22 @@ export class KQLSyntaxError extends Error {
|
|||
shortMessage: string;
|
||||
|
||||
constructor(error: KQLSyntaxErrorData, expression: any) {
|
||||
const translatedExpectations = error.expected.map(expected => {
|
||||
return grammarRuleTranslations[expected.description] || expected.description;
|
||||
});
|
||||
let message = error.message;
|
||||
if (error.expected) {
|
||||
const translatedExpectations = error.expected.map(expected => {
|
||||
return grammarRuleTranslations[expected.description] || expected.description;
|
||||
});
|
||||
|
||||
const translatedExpectationText = translatedExpectations.join(', ');
|
||||
const translatedExpectationText = translatedExpectations.join(', ');
|
||||
|
||||
const message = i18n.translate('data.common.esQuery.kql.errors.syntaxError', {
|
||||
defaultMessage: 'Expected {expectedList} but {foundInput} found.',
|
||||
values: {
|
||||
expectedList: translatedExpectationText,
|
||||
foundInput: error.found ? `"${error.found}"` : endOfInputText,
|
||||
},
|
||||
});
|
||||
message = i18n.translate('data.common.esQuery.kql.errors.syntaxError', {
|
||||
defaultMessage: 'Expected {expectedList} but {foundInput} found.',
|
||||
values: {
|
||||
expectedList: translatedExpectationText,
|
||||
foundInput: error.found ? `"${error.found}"` : endOfInputText,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const fullMessage = [message, expression, repeat('-', error.location.start.offset) + '^'].join(
|
||||
'\n'
|
||||
|
|
Loading…
Reference in a new issue