[ML][Transform] display script_exception compile error message in wizards (#97697)

* ensure error rootCause script gets added to message

* ensure script part of error is shown in DFA wizard

* use isPopulatedObject to check for script field
This commit is contained in:
Melissa Alvarez 2021-04-21 17:52:07 -04:00 committed by GitHub
parent ee7ba71b43
commit 0a0fd695d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View file

@ -14,6 +14,7 @@ import {
isEsErrorBody,
isMLResponseError,
} from './types';
import { isPopulatedObject } from '../object_utils';
export const extractErrorProperties = (error: ErrorType): MLErrorObject => {
// extract properties of the error object from within the response error
@ -73,6 +74,14 @@ export const extractErrorProperties = (error: ErrorType): MLErrorObject => {
error.body.attributes.body.error.caused_by?.caused_by?.reason ||
error.body.attributes.body.error.caused_by?.reason;
}
if (
Array.isArray(error.body.attributes.body.error.root_cause) &&
typeof error.body.attributes.body.error.root_cause[0] === 'object' &&
isPopulatedObject(error.body.attributes.body.error.root_cause[0], ['script'])
) {
errObj.causedBy = error.body.attributes.body.error.root_cause[0].script;
errObj.message += `: '${error.body.attributes.body.error.root_cause[0].script}'`;
}
return errObj;
} else {
return {

View file

@ -12,6 +12,7 @@ export interface EsErrorRootCause {
type: string;
reason: string;
caused_by?: EsErrorRootCause;
script?: string;
}
export interface EsErrorBody {

View file

@ -152,17 +152,22 @@ interface EsError {
reason: string;
line?: number;
col?: number;
script?: string;
}
/**
* Returns an error message based on the root cause
*/
function extractErrorMessage({ type, reason, line, col }: EsError): string {
function extractErrorMessage({ type, reason, script, line, col }: EsError): string {
let message = `[${type}] ${reason}`;
if (line !== undefined && col !== undefined) {
message += `, with line=${line} & col=${col}`;
}
if (script !== undefined) {
message += ` '${script}'`;
}
return message;
}