mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[ES|QL] Fix error handling for ES|QL nested error messages (#170005)
## Summary Fix #170004 This PR fixes the wrong behaviour with message extraction from this type of ES|QL responses. Took also the opportunity to improve the FTR side, with some monaco handlers for errors in the editor and some test cases for errors in ES|QL queries. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
bc90e56be1
commit
2643f504cd
3 changed files with 45 additions and 1 deletions
|
@ -71,6 +71,16 @@ function sanitize(value: string) {
|
|||
return value.replace(/[\(\)]/g, '_');
|
||||
}
|
||||
|
||||
function extractTypeAndReason(attributes: any): { type?: string; reason?: string } {
|
||||
if (['type', 'reason'].every((prop) => prop in attributes)) {
|
||||
return attributes;
|
||||
}
|
||||
if ('error' in attributes) {
|
||||
return extractTypeAndReason(attributes.error);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
interface ESQLSearchParams {
|
||||
time_zone?: string;
|
||||
query: string;
|
||||
|
@ -199,7 +209,7 @@ export const getEsqlFn = ({ getStartDependencies }: EsqlFnArguments) => {
|
|||
if (!error.err) {
|
||||
error.message = `Unexpected error from Elasticsearch: ${error.message}`;
|
||||
} else {
|
||||
const { type, reason } = error.err.attributes;
|
||||
const { type, reason } = extractTypeAndReason(error.err.attributes);
|
||||
if (type === 'parsing_exception') {
|
||||
error.message = `Couldn't parse Elasticsearch ES|QL query. Check your query and try again. Error: ${reason}`;
|
||||
} else {
|
||||
|
|
|
@ -134,5 +134,32 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
|
|||
expect(await cell.getVisibleText()).to.be('1');
|
||||
});
|
||||
});
|
||||
describe('errors', () => {
|
||||
it('should error messages for syntax errors in query', async function () {
|
||||
await PageObjects.discover.selectTextBaseLang();
|
||||
const brokenQueries = [
|
||||
'from logstash-* | limit 10*',
|
||||
'from logstash-* | limit A',
|
||||
'from logstash-* | where a*',
|
||||
'limit 10',
|
||||
];
|
||||
for (const testQuery of brokenQueries) {
|
||||
await monacoEditor.setCodeEditorValue(testQuery);
|
||||
await testSubjects.click('querySubmitButton');
|
||||
await PageObjects.header.waitUntilLoadingHasFinished();
|
||||
await PageObjects.discover.waitUntilSearchingHasFinished();
|
||||
// error in fetching documents because of the invalid query
|
||||
await testSubjects.existOrFail('discoverNoResultsError');
|
||||
const message = await testSubjects.getVisibleText('discoverErrorCalloutMessage');
|
||||
expect(message).to.contain(
|
||||
"[esql] > Couldn't parse Elasticsearch ES|QL query. Check your query and try again."
|
||||
);
|
||||
expect(message).to.not.contain('undefined');
|
||||
if (message.includes('line')) {
|
||||
expect((await monacoEditor.getCurrentMarkers('kibanaCodeEditor')).length).to.eql(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ export class MonacoEditorService extends FtrService {
|
|||
private readonly retry = this.ctx.getService('retry');
|
||||
private readonly browser = this.ctx.getService('browser');
|
||||
private readonly testSubjects = this.ctx.getService('testSubjects');
|
||||
private readonly findService = this.ctx.getService('find');
|
||||
|
||||
public async waitCodeEditorReady(containerTestSubjId: string) {
|
||||
const editorContainer = await this.testSubjects.find(containerTestSubjId);
|
||||
|
@ -52,4 +53,10 @@ export class MonacoEditorService extends FtrService {
|
|||
);
|
||||
});
|
||||
}
|
||||
|
||||
public async getCurrentMarkers(testSubjId: string) {
|
||||
return this.findService.allByCssSelector(
|
||||
`[data-test-subj="${testSubjId}"] .cdr.squiggly-error`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue