Skip to content

Commit

Permalink
[ES|QL] Displays correctly warnings with additional info (elastic#176660
Browse files Browse the repository at this point in the history
)

## Summary

In some cases the warnings come in the format:

`java.lang.IllegalArgumentException: warning message`

We don 't treat these cases correctly and as a result the user gets a
warning which is not helpful at all. This PR fixes it.

**Before**
<img width="621" alt="Screenshot 2024-02-12 at 8 55 14 AM"
src="https://github.com/elastic/kibana/assets/17003240/49f08a32-a125-47e8-b3e0-92cd6a071654">

**With this PR**
<img width="561" alt="image"
src="https://github.com/elastic/kibana/assets/17003240/8ef95a57-1980-4dfe-952a-34b99f7e6708">


### Checklist

- [ ] [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
  • Loading branch information
stratoula authored and CoenWarmer committed Feb 15, 2024
1 parent 84591a7 commit 870c82c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
27 changes: 26 additions & 1 deletion packages/kbn-text-based-editor/src/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('helpers', function () {
]);
});

it('should return the correct array of warnings if multiple warnins are detected', function () {
it('should return the correct array of warnings if multiple warnings are detected', function () {
const warning =
'299 Elasticsearch-8.10.0-SNAPSHOT-adb9fce96079b421c2575f0d2d445f492eb5f075 "Line 1:52: evaluation of [date_parse(geo.dest)] failed, treating result as null. Only first 20 failures recorded.", 299 Elasticsearch-8.10.0-SNAPSHOT-adb9fce96079b421c2575f0d2d445f492eb5f075 "Line 1:84: evaluation of [date_parse(geo.src)] failed, treating result as null. Only first 20 failures recorded."';
expect(parseWarning(warning)).toEqual([
Expand All @@ -115,6 +115,31 @@ describe('helpers', function () {
]);
});

it('should return the correct array of warnings if the message contains additional info', function () {
const warning =
'299 Elasticsearch-8.10.0-SNAPSHOT-adb9fce96079b421c2575f0d2d445f492eb5f075 "Line 1:52: evaluation of [date_parse(geo.dest)] failed, treating result as null. Only first 20 failures recorded.", 299 Elasticsearch-8.10.0-SNAPSHOT-adb9fce96079b421c2575f0d2d445f492eb5f075 "Line 1:84: java.lang.IllegalArgumentException: evaluation of [date_parse(geo.src)] failed, treating result as null. Only first 20 failures recorded."';
expect(parseWarning(warning)).toEqual([
{
endColumn: 138,
endLineNumber: 1,
message:
'evaluation of [date_parse(geo.dest)] failed, treating result as null. Only first 20 failures recorded.',
severity: 4,
startColumn: 52,
startLineNumber: 1,
},
{
endColumn: 169,
endLineNumber: 1,
message:
'evaluation of [date_parse(geo.src)] failed, treating result as null. Only first 20 failures recorded.',
severity: 4,
startColumn: 84,
startLineNumber: 1,
},
]);
});

it('should return the correct array of warnings if multiple warnins are detected without line indicators', function () {
const warning =
'299 Elasticsearch-8.10.0-SNAPSHOT-adb9fce96079b421c2575f0d2d445f492eb5f075 "Field [geo.coordinates] cannot be retrieved, it is unsupported or not indexed; returning null.", 299 Elasticsearch-8.10.0-SNAPSHOT-adb9fce96079b421c2575f0d2d445f492eb5f075 "Field [ip_range] cannot be retrieved, it is unsupported or not indexed; returning null.", 299 Elasticsearch-8.10.0-SNAPSHOT-adb9fce96079b421c2575f0d2d445f492eb5f075 "Field [timestamp_range] cannot be retrieved, it is unsupported or not indexed; returning null."';
Expand Down
6 changes: 4 additions & 2 deletions packages/kbn-text-based-editor/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ export const parseWarning = (warning: string): MonacoMessage[] => {
// if there's line number encoded in the message use it as new positioning
// and replace the actual message without it
if (/Line (\d+):(\d+):/.test(warningMessage)) {
const [encodedLine, encodedColumn, innerMessage] = warningMessage.split(':');
warningMessage = innerMessage;
const [encodedLine, encodedColumn, innerMessage, additionalInfoMessage] =
warningMessage.split(':');
// sometimes the warning comes to the format java.lang.IllegalArgumentException: warning message
warningMessage = additionalInfoMessage ?? innerMessage;
if (!Number.isNaN(Number(encodedColumn))) {
startColumn = Number(encodedColumn);
startLineNumber = Number(encodedLine.replace('Line ', ''));
Expand Down

0 comments on commit 870c82c

Please sign in to comment.