[8.11] [ES|QL] Fix error handling for ES|QL nested error messages (#170005) (#170606)

# Backport

This will backport the following commits from `main` to `8.11`:
- [[ES|QL] Fix error handling for ES|QL nested error messages
(#170005)](https://github.com/elastic/kibana/pull/170005)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Marco
Liberati","email":"dej611@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-11-01T13:30:24Z","message":"[ES|QL]
Fix error handling for ES|QL nested error messages (#170005)\n\n##
Summary\r\n\r\nFix #170004\r\n\r\nThis PR fixes the wrong behaviour with
message extraction from this type\r\nof ES|QL responses.\r\nTook also
the opportunity to improve the FTR side, with some monaco\r\nhandlers
for errors in the editor and some test cases for errors in\r\nES|QL
queries.\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"2643f504cd22c71b8f0a89c554c21313967a709e","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Visualizations","Team:DataDiscovery","backport:prev-minor","Feature:ES|QL","v8.12.0","v8.11.1"],"number":170005,"url":"https://github.com/elastic/kibana/pull/170005","mergeCommit":{"message":"[ES|QL]
Fix error handling for ES|QL nested error messages (#170005)\n\n##
Summary\r\n\r\nFix #170004\r\n\r\nThis PR fixes the wrong behaviour with
message extraction from this type\r\nof ES|QL responses.\r\nTook also
the opportunity to improve the FTR side, with some monaco\r\nhandlers
for errors in the editor and some test cases for errors in\r\nES|QL
queries.\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"2643f504cd22c71b8f0a89c554c21313967a709e"}},"sourceBranch":"main","suggestedTargetBranches":["8.11"],"targetPullRequestStates":[{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/170005","number":170005,"mergeCommit":{"message":"[ES|QL]
Fix error handling for ES|QL nested error messages (#170005)\n\n##
Summary\r\n\r\nFix #170004\r\n\r\nThis PR fixes the wrong behaviour with
message extraction from this type\r\nof ES|QL responses.\r\nTook also
the opportunity to improve the FTR side, with some monaco\r\nhandlers
for errors in the editor and some test cases for errors in\r\nES|QL
queries.\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"2643f504cd22c71b8f0a89c554c21313967a709e"}},{"branch":"8.11","label":"v8.11.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2023-11-06 04:33:02 -05:00 committed by GitHub
parent 42cd5ad661
commit 4e0fc5adaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 1 deletions

View file

@ -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 {

View file

@ -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);
}
}
});
});
});
}

View file

@ -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`
);
}
}