Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ describe('helpers', function () {
},
]);
});

it('should return a string message when error.message is a non-string (e.g. DOMException from aborted fetch)', function () {
const domException = new DOMException('signal is aborted without reason', 'AbortError');
const error = new Error('placeholder');
(error as unknown as { message: unknown }).message = domException;

const result = parseErrors([error], 'FROM logs-*');

expect(result).toHaveLength(1);
expect(typeof result[0].message).toBe('string');
expect(result[0].code).toBe('unknownError');
});
});

describe('parseWarning', function () {
Expand Down
17 changes: 9 additions & 8 deletions src/platform/packages/private/kbn-esql-editor/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,15 @@ const ES_PROBLEM_MARKER_REGEX = /line (\d+):(\d+):/g;

export const parseErrors = (errors: Error[], code: string): MonacoMessage[] => {
return errors.flatMap((error): MonacoMessage[] => {
const errorMessage = typeof error.message === 'string' ? error.message : String(error.message);
try {
if (
// Found while testing random commands (as inlinestats)
!error.message.includes('esql_illegal_argument_exception') &&
error.message.includes('line')
!errorMessage.includes('esql_illegal_argument_exception') &&
errorMessage.includes('line')
) {
const markers: Array<{ line: number; column: number; end: number; start: number }> = [];
for (const match of error.message.matchAll(ES_PROBLEM_MARKER_REGEX)) {
for (const match of errorMessage.matchAll(ES_PROBLEM_MARKER_REGEX)) {
markers.push({
line: Number(match[1]),
column: Number(match[2]),
Expand All @@ -137,8 +138,8 @@ export const parseErrors = (errors: Error[], code: string): MonacoMessage[] => {

if (markers.length > 0) {
return markers.map((marker, i) => {
const messageEnd = i + 1 < markers.length ? markers[i + 1].start : error.message.length;
const message = error.message.slice(marker.end, messageEnd).replace(/\s+$/, '');
const messageEnd = i + 1 < markers.length ? markers[i + 1].start : errorMessage.length;
const message = errorMessage.slice(marker.end, messageEnd).replace(/\s+$/, '');
const bracketed = message.match(/\[([^\]]*)\]/);
const errorLength = bracketed ? bracketed[1].length : 10;
return {
Expand All @@ -154,7 +155,7 @@ export const parseErrors = (errors: Error[], code: string): MonacoMessage[] => {
}
}

if (error.message.includes('expression was aborted')) {
if (errorMessage.includes('expression was aborted')) {
return [
{
message: i18n.translate('esqlEditor.query.aborted', {
Expand All @@ -172,7 +173,7 @@ export const parseErrors = (errors: Error[], code: string): MonacoMessage[] => {

return [
{
message: error.message,
message: errorMessage,
startColumn: 1,
startLineNumber: 1,
endColumn: 10,
Expand All @@ -184,7 +185,7 @@ export const parseErrors = (errors: Error[], code: string): MonacoMessage[] => {
} catch (e) {
return [
{
message: error.message,
message: errorMessage,
startColumn: 1,
startLineNumber: 1,
endColumn: 10,
Expand Down
Loading