[ML] Moves shared code to @kbn/ml-error-utils. (#155372)

- Moves code from `x-pack/plugins/ml/common/util/errors` that was shared
via `x-pack/plugins/ml/public/shared.ts` to `@kbn/ml-error-utils`.
- `data_visualizer` and `aiops` plugins now use that package instead of
code duplication.
This commit is contained in:
Walter Rafelsberger 2023-04-22 09:25:37 +02:00 committed by GitHub
parent 1bbaa5a62f
commit d6d933a2af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
91 changed files with 451 additions and 613 deletions

1
.github/CODEOWNERS vendored
View file

@ -455,6 +455,7 @@ src/plugins/maps_ems @elastic/kibana-gis
x-pack/plugins/maps @elastic/kibana-gis
x-pack/packages/ml/agg_utils @elastic/ml-ui
x-pack/packages/ml/date_picker @elastic/ml-ui
x-pack/packages/ml/error_utils @elastic/ml-ui
x-pack/packages/ml/is_defined @elastic/ml-ui
x-pack/packages/ml/is_populated_object @elastic/ml-ui
x-pack/packages/ml/local_storage @elastic/ml-ui

View file

@ -470,6 +470,7 @@
"@kbn/maps-plugin": "link:x-pack/plugins/maps",
"@kbn/ml-agg-utils": "link:x-pack/packages/ml/agg_utils",
"@kbn/ml-date-picker": "link:x-pack/packages/ml/date_picker",
"@kbn/ml-error-utils": "link:x-pack/packages/ml/error_utils",
"@kbn/ml-is-defined": "link:x-pack/packages/ml/is_defined",
"@kbn/ml-is-populated-object": "link:x-pack/packages/ml/is_populated_object",
"@kbn/ml-local-storage": "link:x-pack/packages/ml/local_storage",

View file

@ -904,6 +904,8 @@
"@kbn/ml-agg-utils/*": ["x-pack/packages/ml/agg_utils/*"],
"@kbn/ml-date-picker": ["x-pack/packages/ml/date_picker"],
"@kbn/ml-date-picker/*": ["x-pack/packages/ml/date_picker/*"],
"@kbn/ml-error-utils": ["x-pack/packages/ml/error_utils"],
"@kbn/ml-error-utils/*": ["x-pack/packages/ml/error_utils/*"],
"@kbn/ml-is-defined": ["x-pack/packages/ml/is_defined"],
"@kbn/ml-is-defined/*": ["x-pack/packages/ml/is_defined/*"],
"@kbn/ml-is-populated-object": ["x-pack/packages/ml/is_populated_object"],

View file

@ -0,0 +1,3 @@
# @kbn/ml-error-utils
Empty package generated by @kbn/generate

View file

@ -5,8 +5,8 @@
* 2.0.
*/
export { MLRequestFailure } from './request_error';
export { extractErrorMessage, extractErrorProperties } from './process_errors';
export { MLRequestFailure } from './src/request_error';
export { extractErrorMessage, extractErrorProperties } from './src/process_errors';
export type {
ErrorType,
ErrorMessage,
@ -14,6 +14,8 @@ export type {
EsErrorRootCause,
MLErrorObject,
MLHttpFetchError,
MLHttpFetchErrorBase,
MLResponseError,
} from './types';
export { isBoomError, isErrorString, isEsErrorBody, isMLResponseError } from './types';
QueryErrorMessage,
} from './src/types';
export { isBoomError, isErrorString, isEsErrorBody, isMLResponseError } from './src/types';

View file

@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
module.exports = {
preset: '@kbn/test',
rootDir: '../../../..',
roots: ['<rootDir>/x-pack/packages/ml/error_utils'],
};

View file

@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/ml-error-utils",
"owner": "@elastic/ml-ui"
}

View file

@ -0,0 +1,6 @@
{
"name": "@kbn/ml-error-utils",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0"
}

View file

@ -7,7 +7,8 @@
import Boom from '@hapi/boom';
import { extractErrorMessage, MLHttpFetchError, EsErrorBody } from '.';
import { extractErrorMessage } from './process_errors';
import { type MLHttpFetchError, type EsErrorBody } from './types';
describe('ML - error message utils', () => {
describe('extractErrorMessage', () => {

View file

@ -16,15 +16,19 @@ import {
isMLResponseError,
} from './types';
/**
* Extract properties of the error object from within the response error
* coming from Kibana, Elasticsearch, and our own ML messages.
*
* @param {ErrorType} error
* @returns {MLErrorObject}
*/
export const extractErrorProperties = (error: ErrorType): MLErrorObject => {
// extract properties of the error object from within the response error
// coming from Kibana, Elasticsearch, and our own ML messages
// some responses contain raw es errors as part of a bulk response
// e.g. if some jobs fail the action in a bulk request
if (isEsErrorBody(error)) {
return {
message: error.error.reason,
message: error.error.reason ?? '',
statusCode: error.status,
fullError: error,
};
@ -79,7 +83,7 @@ export const extractErrorProperties = (error: ErrorType): MLErrorObject => {
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.causedBy = error.body.attributes.body.error.root_cause[0].script as string;
errObj.message += `: '${error.body.attributes.body.error.root_cause[0].script}'`;
}
return errObj;
@ -103,8 +107,14 @@ export const extractErrorProperties = (error: ErrorType): MLErrorObject => {
};
};
/**
* Extract only the error message within the response error
* coming from Kibana, Elasticsearch, and our own ML messages.
*
* @param {ErrorType} error
* @returns {string}
*/
export const extractErrorMessage = (error: ErrorType): string => {
// extract only the error message within the response error coming from Kibana, Elasticsearch, and our own ML messages
const errorObj = extractErrorProperties(error);
return errorObj.message;
};

View file

@ -7,7 +7,22 @@
import { MLErrorObject, ErrorType } from './types';
/**
* ML Request Failure
*
* @export
* @class MLRequestFailure
* @typedef {MLRequestFailure}
* @extends {Error}
*/
export class MLRequestFailure extends Error {
/**
* Creates an instance of MLRequestFailure.
*
* @constructor
* @param {MLErrorObject} error
* @param {ErrorType} resp
*/
constructor(error: MLErrorObject, resp: ErrorType) {
super(error.message);
Object.setPrototypeOf(this, new.target.prototype);

View file

@ -0,0 +1,196 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type Boom from '@hapi/boom';
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type { IHttpFetchError } from '@kbn/core-http-browser';
import { isPopulatedObject } from '@kbn/ml-is-populated-object';
/**
* Short hand type of estypes.ErrorCause.
* @typedef {EsErrorRootCause}
*/
export type EsErrorRootCause = estypes.ErrorCause;
/**
* Short hand type of estypes.ErrorResponseBase.
* @typedef {EsErrorBody}
*/
export type EsErrorBody = estypes.ErrorResponseBase;
/**
* ML Response error
* @export
* @interface MLResponseError
* @typedef {MLResponseError}
*/
export interface MLResponseError {
/**
* statusCode
* @type {number}
*/
statusCode: number;
/**
* error
* @type {string}
*/
error: string;
/**
* message
* @type {string}
*/
message: string;
/**
* Optional attributes
* @type {?{
body: EsErrorBody;
}}
*/
attributes?: {
body: EsErrorBody;
};
}
/**
* Interface holding error message
* @export
* @interface ErrorMessage
* @typedef {ErrorMessage}
*/
export interface ErrorMessage {
/**
* message
* @type {string}
*/
message: string;
}
/**
* To be used for client side errors related to search query bars.
*/
export interface QueryErrorMessage extends ErrorMessage {
/**
* query
* @type {string}
*/
query: string;
}
/**
* ML Error Object
* @export
* @interface MLErrorObject
* @typedef {MLErrorObject}
*/
export interface MLErrorObject {
/**
* Optional causedBy
* @type {?string}
*/
causedBy?: string;
/**
* message
* @type {string}
*/
message: string;
/**
* Optional statusCode
* @type {?number}
*/
statusCode?: number;
/**
* Optional fullError
* @type {?EsErrorBody}
*/
fullError?: EsErrorBody;
}
/**
* MLHttpFetchErrorBase
* @export
* @interface MLHttpFetchErrorBase
* @typedef {MLHttpFetchErrorBase}
* @template T
* @extends {IHttpFetchError<T>}
*/
export interface MLHttpFetchErrorBase<T> extends IHttpFetchError<T> {
/**
* body
* @type {T}
*/
body: T;
}
/**
* MLHttpFetchError
* @export
* @typedef {MLHttpFetchError}
*/
export type MLHttpFetchError = MLHttpFetchErrorBase<MLResponseError>;
/**
* Union type of error types
* @export
* @typedef {ErrorType}
*/
export type ErrorType = MLHttpFetchError | EsErrorBody | Boom.Boom | string | undefined;
/**
* Type guard to check if error is of type EsErrorBody
* @export
* @param {unknown} error
* @returns {error is EsErrorBody}
*/
export function isEsErrorBody(error: unknown): error is EsErrorBody {
return isPopulatedObject(error, ['error']) && isPopulatedObject(error.error, ['reason']);
}
/**
* Type guard to check if error is a string.
* @export
* @param {unknown} error
* @returns {error is string}
*/
export function isErrorString(error: unknown): error is string {
return typeof error === 'string';
}
/**
* Type guard to check if error is of type ErrorMessage.
* @export
* @param {unknown} error
* @returns {error is ErrorMessage}
*/
export function isErrorMessage(error: unknown): error is ErrorMessage {
return isPopulatedObject(error, ['message']) && typeof error.message === 'string';
}
/**
* Type guard to check if error is of type MLResponseError.
* @export
* @param {unknown} error
* @returns {error is MLResponseError}
*/
export function isMLResponseError(error: unknown): error is MLResponseError {
return (
isPopulatedObject(error, ['body']) &&
isPopulatedObject(error.body, ['message']) &&
'message' in error.body
);
}
/**
* Type guard to check if error is of type Boom.
* @export
* @param {unknown} error
* @returns {error is Boom.Boom}
*/
export function isBoomError(error: unknown): error is Boom.Boom {
return isPopulatedObject(error, ['isBoom']) && error.isBoom === true;
}

View file

@ -0,0 +1,22 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
"react"
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/ml-is-populated-object",
"@kbn/core-http-browser",
]
}

View file

@ -1,193 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
// TODO Consolidate with duplicate error utils file in
// `x-pack/plugins/data_visualizer/public/application/index_data_visualizer/utils/error_utils.ts`
import type { IHttpFetchError } from '@kbn/core-http-browser';
import Boom from '@hapi/boom';
import { isPopulatedObject } from '@kbn/ml-is-populated-object';
export interface WrappedError {
body: {
attributes: {
body: EsErrorBody;
};
message: Boom.Boom;
};
statusCode: number;
}
export interface EsErrorRootCause {
type: string;
reason: string;
caused_by?: EsErrorRootCause;
script?: string;
}
export interface EsErrorBody {
error: {
root_cause?: EsErrorRootCause[];
caused_by?: EsErrorRootCause;
type: string;
reason: string;
};
status: number;
}
export interface AiOpsResponseError {
statusCode: number;
error: string;
message: string;
attributes?: {
body: EsErrorBody;
};
}
export interface ErrorMessage {
message: string;
}
export interface AiOpsErrorObject {
causedBy?: string;
message: string;
statusCode?: number;
fullError?: EsErrorBody;
}
export interface AiOpsHttpFetchError<T> extends IHttpFetchError {
body: T;
}
export type ErrorType =
| WrappedError
| AiOpsHttpFetchError<AiOpsResponseError>
| EsErrorBody
| Boom.Boom
| string
| undefined;
export function isEsErrorBody(error: any): error is EsErrorBody {
return error && error.error?.reason !== undefined;
}
export function isErrorString(error: any): error is string {
return typeof error === 'string';
}
export function isErrorMessage(error: any): error is ErrorMessage {
return error && error.message !== undefined && typeof error.message === 'string';
}
export function isAiOpsResponseError(error: any): error is AiOpsResponseError {
return typeof error.body === 'object' && 'message' in error.body;
}
export function isBoomError(error: any): error is Boom.Boom {
return error?.isBoom === true;
}
export function isWrappedError(error: any): error is WrappedError {
return error && isBoomError(error.body?.message) === true;
}
export const extractErrorProperties = (error: ErrorType): AiOpsErrorObject => {
// extract properties of the error object from within the response error
// coming from Kibana, Elasticsearch, and our own AiOps messages
// some responses contain raw es errors as part of a bulk response
// e.g. if some jobs fail the action in a bulk request
if (isEsErrorBody(error)) {
return {
message: error.error.reason,
statusCode: error.status,
fullError: error,
};
}
if (isErrorString(error)) {
return {
message: error,
};
}
if (isWrappedError(error)) {
return error.body.message?.output?.payload;
}
if (isBoomError(error)) {
return {
message: error.output.payload.message,
statusCode: error.output.payload.statusCode,
};
}
if (error?.body === undefined && !error?.message) {
return {
message: '',
};
}
if (typeof error.body === 'string') {
return {
message: error.body,
};
}
if (isAiOpsResponseError(error)) {
if (
typeof error.body.attributes === 'object' &&
typeof error.body.attributes.body?.error?.reason === 'string'
) {
const errObj: AiOpsErrorObject = {
message: error.body.attributes.body.error.reason,
statusCode: error.body.statusCode,
fullError: error.body.attributes.body,
};
if (
typeof error.body.attributes.body.error.caused_by === 'object' &&
(typeof error.body.attributes.body.error.caused_by?.reason === 'string' ||
typeof error.body.attributes.body.error.caused_by?.caused_by?.reason === 'string')
) {
errObj.causedBy =
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 {
message: error.body.message,
statusCode: error.body.statusCode,
};
}
}
if (isErrorMessage(error)) {
return {
message: error.message,
};
}
// If all else fail return an empty message instead of JSON.stringify
return {
message: '',
};
};
export const extractErrorMessage = (error: ErrorType): string => {
// extract only the error message within the response error coming from Kibana, Elasticsearch, and our own ML messages
const errorObj = extractErrorProperties(error);
return errorObj.message;
};

View file

@ -12,10 +12,10 @@ import { i18n } from '@kbn/i18n';
import type { ToastsStart } from '@kbn/core/public';
import { stringHash } from '@kbn/ml-string-hash';
import { createRandomSamplerWrapper } from '@kbn/ml-random-sampler-utils';
import { extractErrorProperties } from '@kbn/ml-error-utils';
import { RANDOM_SAMPLER_SEED } from '../../common/constants';
import { extractErrorProperties } from '../application/utils/error_utils';
import {
DocumentCountStats,
getDocumentCountStatsRequest,

View file

@ -34,7 +34,6 @@
"@kbn/ui-theme",
"@kbn/i18n-react",
"@kbn/rison",
"@kbn/core-http-browser",
"@kbn/aiops-components",
"@kbn/aiops-utils",
"@kbn/licensing-plugin",
@ -51,6 +50,7 @@
"@kbn/ml-route-utils",
"@kbn/unified-field-list-plugin",
"@kbn/ml-random-sampler-utils",
"@kbn/ml-error-utils",
],
"exclude": [
"target/**/*",

View file

@ -8,14 +8,14 @@
import { EuiCallOut } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import React from 'react';
import { DVErrorObject } from '../../../../../index_data_visualizer/utils/error_utils';
import { MLErrorObject } from '@kbn/ml-error-utils';
export const ErrorMessageContent = ({
fieldName,
error,
}: {
fieldName: string;
error: DVErrorObject;
error: MLErrorObject;
}) => {
return (
<EuiCallOut heading="p" color="danger" size="s">

View file

@ -16,6 +16,7 @@ import type {
IKibanaSearchResponse,
ISearchOptions,
} from '@kbn/data-plugin/common';
import { extractErrorProperties } from '@kbn/ml-error-utils';
import { useDataVisualizerKibana } from '../../kibana_context';
import {
AggregatableFieldOverallStats,
@ -29,7 +30,6 @@ import {
} from '../search_strategy/requests/overall_stats';
import type { OverallStats } from '../types/overall_stats';
import { getDefaultPageState } from '../components/index_data_visualizer_view/index_data_visualizer_view';
import { extractErrorProperties } from '../utils/error_utils';
import {
DataStatsFetchProgress,
isRandomSamplingOption,

View file

@ -15,6 +15,7 @@ import type {
ISearchStart,
} from '@kbn/data-plugin/public';
import { isPopulatedObject } from '@kbn/ml-is-populated-object';
import { extractErrorProperties } from '@kbn/ml-error-utils';
import { processTopValues } from './utils';
import { buildAggregationWithSamplingOption } from './build_random_sampler_agg';
@ -25,7 +26,6 @@ import type {
FieldStatsCommonRequestParams,
} from '../../../../../common/types/field_stats';
import { FieldStatsError, isIKibanaSearchResponse } from '../../../../../common/types/field_stats';
import { extractErrorProperties } from '../../utils/error_utils';
export const getBooleanFieldsStatsRequest = (
params: FieldStatsCommonRequestParams,

View file

@ -16,11 +16,11 @@ import type {
ISearchStart,
} from '@kbn/data-plugin/public';
import { isPopulatedObject } from '@kbn/ml-is-populated-object';
import { extractErrorProperties } from '@kbn/ml-error-utils';
import { buildAggregationWithSamplingOption } from './build_random_sampler_agg';
import type { FieldStatsCommonRequestParams } from '../../../../../common/types/field_stats';
import type { Field, DateFieldStats, Aggs } from '../../../../../common/types/field_stats';
import { FieldStatsError, isIKibanaSearchResponse } from '../../../../../common/types/field_stats';
import { extractErrorProperties } from '../../utils/error_utils';
export const getDateFieldsStatsRequest = (
params: FieldStatsCommonRequestParams,

View file

@ -17,6 +17,7 @@ import type {
import { isPopulatedObject } from '@kbn/ml-is-populated-object';
import type { SearchHit } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { buildBaseFilterCriteria } from '@kbn/ml-query-utils';
import { extractErrorProperties } from '@kbn/ml-error-utils';
import { getUniqGeoOrStrExamples } from '../../../common/util/example_utils';
import type {
Field,
@ -24,7 +25,6 @@ import type {
FieldStatsCommonRequestParams,
} from '../../../../../common/types/field_stats';
import { FieldStatsError, isIKibanaSearchResponse } from '../../../../../common/types/field_stats';
import { extractErrorProperties } from '../../utils/error_utils';
import { MAX_EXAMPLES_DEFAULT } from './constants';
export const getFieldExamplesRequest = (params: FieldStatsCommonRequestParams, field: Field) => {

View file

@ -18,6 +18,7 @@ import type {
import type { ISearchStart } from '@kbn/data-plugin/public';
import { isPopulatedObject } from '@kbn/ml-is-populated-object';
import { isDefined } from '@kbn/ml-is-defined';
import { extractErrorProperties } from '@kbn/ml-error-utils';
import { processTopValues } from './utils';
import { buildAggregationWithSamplingOption } from './build_random_sampler_agg';
import { MAX_PERCENT, PERCENTILE_SPACING, SAMPLER_TOP_TERMS_THRESHOLD } from './constants';
@ -32,7 +33,6 @@ import type {
FieldStatsError,
} from '../../../../../common/types/field_stats';
import { processDistributionData } from '../../utils/process_distribution_data';
import { extractErrorProperties } from '../../utils/error_utils';
import {
isIKibanaSearchResponse,
isNormalSamplingOption,

View file

@ -16,6 +16,7 @@ import type {
ISearchStart,
} from '@kbn/data-plugin/public';
import { isPopulatedObject } from '@kbn/ml-is-populated-object';
import { extractErrorProperties } from '@kbn/ml-error-utils';
import { processTopValues } from './utils';
import { buildAggregationWithSamplingOption } from './build_random_sampler_agg';
import { SAMPLER_TOP_TERMS_THRESHOLD } from './constants';
@ -26,7 +27,6 @@ import type {
StringFieldStats,
} from '../../../../../common/types/field_stats';
import { FieldStatsError, isIKibanaSearchResponse } from '../../../../../common/types/field_stats';
import { extractErrorProperties } from '../../utils/error_utils';
export const getStringFieldStatsRequest = (
params: FieldStatsCommonRequestParams,

View file

@ -1,184 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { IHttpFetchError } from '@kbn/core-http-browser';
import Boom from '@hapi/boom';
import { isPopulatedObject } from '@kbn/ml-is-populated-object';
export interface WrappedError {
body: {
attributes: {
body: EsErrorBody;
};
message: Boom.Boom;
};
statusCode: number;
}
export interface EsErrorRootCause {
type: string;
reason: string;
caused_by?: EsErrorRootCause;
script?: string;
}
export interface EsErrorBody {
error: {
root_cause?: EsErrorRootCause[];
caused_by?: EsErrorRootCause;
type: string;
reason: string;
};
status: number;
}
export interface DVResponseError {
statusCode: number;
error: string;
message: string;
attributes?: {
body: EsErrorBody;
};
}
export interface ErrorMessage {
message: string;
}
export interface DVErrorObject {
causedBy?: string;
message: string;
statusCode?: number;
fullError?: EsErrorBody;
}
export interface DVHttpFetchError<T> extends IHttpFetchError {
body: T;
}
export type ErrorType =
| WrappedError
| DVHttpFetchError<DVResponseError>
| EsErrorBody
| Boom.Boom
| string
| undefined;
export function isEsErrorBody(error: any): error is EsErrorBody {
return error && error.error?.reason !== undefined;
}
export function isErrorString(error: any): error is string {
return typeof error === 'string';
}
export function isErrorMessage(error: any): error is ErrorMessage {
return error && error.message !== undefined && typeof error.message === 'string';
}
export function isDVResponseError(error: any): error is DVResponseError {
return typeof error.body === 'object' && 'message' in error.body;
}
export function isBoomError(error: any): error is Boom.Boom {
return error?.isBoom === true;
}
export function isWrappedError(error: any): error is WrappedError {
return error && isBoomError(error.body?.message) === true;
}
export const extractErrorProperties = (error: ErrorType): DVErrorObject => {
// extract properties of the error object from within the response error
// coming from Kibana, Elasticsearch, and our own DV messages
// some responses contain raw es errors as part of a bulk response
// e.g. if some jobs fail the action in a bulk request
if (isEsErrorBody(error)) {
return {
message: error.error.reason,
statusCode: error.status,
fullError: error,
};
}
if (isErrorString(error)) {
return {
message: error,
};
}
if (isWrappedError(error)) {
return error.body.message?.output?.payload;
}
if (isBoomError(error)) {
return {
message: error.output.payload.message,
statusCode: error.output.payload.statusCode,
};
}
if (error?.body === undefined && !error?.message) {
return {
message: '',
};
}
if (typeof error.body === 'string') {
return {
message: error.body,
};
}
if (isDVResponseError(error)) {
if (
typeof error.body.attributes === 'object' &&
typeof error.body.attributes.body?.error?.reason === 'string'
) {
const errObj: DVErrorObject = {
message: error.body.attributes.body.error.reason,
statusCode: error.body.statusCode,
fullError: error.body.attributes.body,
};
if (
typeof error.body.attributes.body.error.caused_by === 'object' &&
(typeof error.body.attributes.body.error.caused_by?.reason === 'string' ||
typeof error.body.attributes.body.error.caused_by?.caused_by?.reason === 'string')
) {
errObj.causedBy =
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 {
message: error.body.message,
statusCode: error.body.statusCode,
};
}
}
if (isErrorMessage(error)) {
return {
message: error.message,
};
}
// If all else fail return an empty message instead of JSON.stringify
return {
message: '',
};
};

View file

@ -17,7 +17,6 @@
"@kbn/cloud-chat-plugin",
"@kbn/cloud-plugin",
"@kbn/core-execution-context-common",
"@kbn/core-http-browser",
"@kbn/core",
"@kbn/custom-integrations-plugin",
"@kbn/data-plugin",
@ -60,6 +59,7 @@
"@kbn/unified-search-plugin",
"@kbn/usage-collection-plugin",
"@kbn/utility-types",
"@kbn/ml-error-utils",
],
"exclude": [
"target/**/*",

View file

@ -14,8 +14,3 @@ export const SEARCH_QUERY_LANGUAGE = {
} as const;
export type SearchQueryLanguage = typeof SEARCH_QUERY_LANGUAGE[keyof typeof SEARCH_QUERY_LANGUAGE];
export interface ErrorMessage {
query: string;
message: string;
}

View file

@ -16,7 +16,6 @@ export {
export { getSeverityColor, getSeverityType } from './util/anomaly_utils';
export { composeValidators, patternValidator } from './util/validators';
export { isRuntimeMappings, isRuntimeField } from './util/runtime_field_utils';
export { extractErrorMessage } from './util/errors';
export type { RuntimeMappings } from './types/fields';
export { getDefaultCapabilities as getDefaultMlCapabilities } from './types/capabilities';
export { DATAFEED_STATE, JOB_STATE } from './constants/states';

View file

@ -9,7 +9,7 @@ import Boom from '@hapi/boom';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { isPopulatedObject } from '@kbn/ml-is-populated-object';
import { EsErrorBody } from '../util/errors';
import { EsErrorBody } from '@kbn/ml-error-utils';
import { ANALYSIS_CONFIG_TYPE } from '../constants/data_frame_analytics';
import type { UrlConfig } from './custom_urls';

View file

@ -5,10 +5,10 @@
* 2.0.
*/
import type { ErrorType } from '@kbn/ml-error-utils';
import { Job, JobStats, IndicesOptions } from './anomaly_detection_jobs';
import { RuntimeMappings } from './fields';
import { ES_AGGREGATION } from '../constants/aggregation_types';
import { ErrorType } from '../util/errors';
export interface MlJobsResponse {
jobs: Job[];

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import type { ErrorType } from '../util/errors';
import type { ErrorType } from '@kbn/ml-error-utils';
export interface DatafeedValidationResponse {
valid: boolean;

View file

@ -6,8 +6,8 @@
*/
import type { SavedObjectAttributes } from '@kbn/core/types';
import type { ErrorType } from '@kbn/ml-error-utils';
import type { Datafeed, Job } from './anomaly_detection_jobs';
import type { ErrorType } from '../util/errors';
export interface ModuleJob {
id: string;

View file

@ -7,7 +7,7 @@
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type { LineAnnotationDatum, RectAnnotationDatum } from '@elastic/charts';
import type { ErrorType } from '../util/errors';
import type { ErrorType } from '@kbn/ml-error-utils';
import type { EntityField } from '../util/anomaly_utils';
import type { Datafeed, JobId, ModelSnapshot } from './anomaly_detection_jobs';
import { ES_AGGREGATION, ML_JOB_AGGREGATION } from '../constants/aggregation_types';

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import type { ErrorType } from '../util/errors';
import type { ErrorType } from '@kbn/ml-error-utils';
export type JobType = 'anomaly-detector' | 'data-frame-analytics';
export type TrainedModelType = 'trained-model';

View file

@ -1,74 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { IHttpFetchError } from '@kbn/core-http-browser';
import Boom from '@hapi/boom';
export interface EsErrorRootCause {
type: string;
reason: string;
caused_by?: EsErrorRootCause;
script?: string;
}
export interface EsErrorBody {
error: {
root_cause?: EsErrorRootCause[];
caused_by?: EsErrorRootCause;
type: string;
reason: string;
};
status: number;
}
export interface MLResponseError {
statusCode: number;
error: string;
message: string;
attributes?: {
body: EsErrorBody;
};
}
export interface ErrorMessage {
message: string;
}
export interface MLErrorObject {
causedBy?: string;
message: string;
statusCode?: number;
fullError?: EsErrorBody;
}
export interface MLHttpFetchErrorBase<T> extends IHttpFetchError<T> {
body: T;
}
export type MLHttpFetchError = MLHttpFetchErrorBase<MLResponseError>;
export type ErrorType = MLHttpFetchError | EsErrorBody | Boom.Boom | string | undefined;
export function isEsErrorBody(error: any): error is EsErrorBody {
return error && error.error?.reason !== undefined;
}
export function isErrorString(error: any): error is string {
return typeof error === 'string';
}
export function isErrorMessage(error: any): error is ErrorMessage {
return error && error.message !== undefined && typeof error.message === 'string';
}
export function isMLResponseError(error: any): error is MLResponseError {
return typeof error.body === 'object' && 'message' in error.body;
}
export function isBoomError(error: any): error is Boom.Boom {
return error?.isBoom === true;
}

View file

@ -12,16 +12,14 @@ import { useMemo } from 'react';
import { EuiDataGridCellValueElementProps, EuiDataGridStyle } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { CoreSetup } from '@kbn/core/public';
import type { DataView, DataViewField } from '@kbn/data-views-plugin/common';
import { ES_FIELD_TYPES, KBN_FIELD_TYPES } from '@kbn/field-types';
import { getNestedProperty } from '@kbn/ml-nested-property';
import { isCounterTimeSeriesMetric } from '@kbn/ml-agg-utils';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { DEFAULT_RESULTS_FIELD } from '../../../../common/constants/data_frame_analytics';
import { extractErrorMessage } from '../../../../common/util/errors';
import {
FeatureImportance,
FeatureImportanceClassName,

View file

@ -6,9 +6,7 @@
*/
import React, { FC, useState, useEffect, useCallback, useMemo } from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import useDebounce from 'react-use/lib/useDebounce';
import { i18n } from '@kbn/i18n';
import {
EuiFlyout,
@ -29,6 +27,10 @@ import {
EuiFieldText,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { type ErrorType, extractErrorProperties } from '@kbn/ml-error-utils';
import type { DataFrameAnalyticsConfig } from '../../../data_frame_analytics/common';
import type { JobType } from '../../../../../common/types/saved_objects';
import { useMlApiContext, useMlKibana } from '../../../contexts/kibana';
@ -38,7 +40,6 @@ import { toastNotificationServiceProvider } from '../../../services/toast_notifi
import { JobImportService } from './jobs_import_service';
import { useValidateIds } from './validate';
import type { ImportedAdJob, JobIdObject, SkippedJobs } from './jobs_import_service';
import { ErrorType, extractErrorProperties } from '../../../../../common/util/errors';
interface Props {
isDisabled: boolean;

View file

@ -11,8 +11,6 @@
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import {
EuiButton,
@ -31,6 +29,10 @@ import {
EuiTitle,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { DetectorDescriptionList } from './components/detector_description_list';
import { ActionsSection } from './actions_section';
import { checkPermission } from '../../capabilities/check_capabilities';
@ -54,7 +56,6 @@ import { getPartitioningFieldNames } from '../../../../common/util/job_utils';
import { withKibana } from '@kbn/kibana-react-plugin/public';
import { mlJobService } from '../../services/job_service';
import { ml } from '../../services/ml_api_service';
import { extractErrorMessage } from '../../../../common/util/errors';
class RuleEditorFlyoutUI extends Component {
static propTypes = {

View file

@ -6,9 +6,8 @@
*/
import React, { useMemo, useEffect, useState, FC, useCallback } from 'react';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import rison from '@kbn/rison';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import {
EuiCallOut,
EuiComboBox,
@ -23,16 +22,17 @@ import {
EuiSwitch,
} from '@elastic/eui';
import rison from '@kbn/rison';
import { i18n } from '@kbn/i18n';
import { Query } from '@kbn/data-plugin/common/query';
import { DataView } from '@kbn/data-views-plugin/public';
import { stringHash } from '@kbn/ml-string-hash';
import { extractErrorMessage } from '../../../../common';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { isRuntimeMappings } from '../../../../common/util/runtime_field_utils';
import { RuntimeMappings } from '../../../../common/types/fields';
import { getCombinedRuntimeMappings } from '../data_grid';
import { getCombinedRuntimeMappings } from '../data_grid';
import { useMlApiContext, useMlKibana } from '../../contexts/kibana';
import { getProcessedFields } from '../data_grid';

View file

@ -9,9 +9,9 @@ import { useEffect } from 'react';
import { BehaviorSubject, Subscription } from 'rxjs';
import { distinctUntilChanged, filter } from 'rxjs/operators';
import { cloneDeep } from 'lodash';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { ml } from '../../services/ml_api_service';
import { Dictionary } from '../../../../common/types/common';
import { extractErrorMessage } from '../../../../common/util/errors';
import {
ClassificationEvaluateResponse,
EvaluateMetrics,

View file

@ -6,7 +6,7 @@
*/
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { extractErrorMessage } from '../../../../common/util/errors';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { EsSorting, UseDataGridReturnType, getProcessedFields } from '../../components/data_grid';
import { ml } from '../../services/ml_api_service';

View file

@ -10,8 +10,7 @@ import { useEffect, useState } from 'react';
import { i18n } from '@kbn/i18n';
import type { DataView } from '@kbn/data-views-plugin/public';
import { extractErrorMessage } from '../../../../common/util/errors';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { getDataViewIdFromName } from '../../util/index_utils';
import { ml } from '../../services/ml_api_service';

View file

@ -10,11 +10,11 @@ import { debounce } from 'lodash';
import { EuiCallOut, EuiFieldText, EuiForm, EuiFormRow, EuiSpacer } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { CodeEditor } from '@kbn/kibana-react-plugin/public';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { useNotifications } from '../../../../../contexts/kibana';
import { ml } from '../../../../../services/ml_api_service';
import { extractErrorMessage } from '../../../../../../../common/util/errors';
import { CreateAnalyticsFormProps } from '../../../analytics_management/hooks/use_create_analytics_form';
import { CreateStep } from '../create_step';
import { ANALYTICS_STEPS } from '../../page';

View file

@ -9,6 +9,7 @@ import React, { FC, Fragment, useRef, useEffect, useMemo, useState } from 'react
import { debounce } from 'lodash';
import { EuiFieldText, EuiFormRow, EuiLink, EuiSpacer, EuiSwitch, EuiTextArea } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { useMlKibana } from '../../../../../contexts/kibana';
import { CreateAnalyticsStepProps } from '../../../analytics_management/hooks/use_create_analytics_form';
@ -16,7 +17,6 @@ import { JOB_ID_MAX_LENGTH } from '../../../../../../../common/constants/validat
import { ContinueButton } from '../continue_button';
import { ANALYTICS_STEPS } from '../../page';
import { ml } from '../../../../../services/ml_api_service';
import { extractErrorMessage } from '../../../../../../../common/util/errors';
const DEFAULT_RESULTS_FIELD = 'ml';

View file

@ -5,8 +5,9 @@
* 2.0.
*/
import { extractErrorProperties } from '@kbn/ml-error-utils';
import { ml } from '../../../../../services/ml_api_service';
import { extractErrorProperties } from '../../../../../../../common/util/errors';
import {
DfAnalyticsExplainResponse,
FieldSelectionItem,

View file

@ -6,17 +6,19 @@
*/
import React, { FC, useEffect, useMemo, useState } from 'react';
import { EuiForm } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { debounce } from 'lodash';
import { EuiForm } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { CreateAnalyticsStepProps } from '../../../analytics_management/hooks/use_create_analytics_form';
import { ValidationStep } from './validation_step';
import { ValidationStepDetails } from './validation_step_details';
import { ANALYTICS_STEPS } from '../../page';
import { useMlApiContext } from '../../../../../contexts/kibana';
import { getJobConfigFromFormState } from '../../../analytics_management/hooks/use_create_analytics_form/state';
import { extractErrorMessage } from '../../../../../../../common/util/errors';
import {
CalloutMessage,
ValidateAnalyticsJobResponse,

View file

@ -9,11 +9,13 @@ import { useEffect, useMemo, useState } from 'react';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { EuiDataGridColumn } from '@elastic/eui';
import { CoreSetup } from '@kbn/core/public';
import { CoreSetup } from '@kbn/core/public';
import type { DataView } from '@kbn/data-views-plugin/public';
import { isPopulatedObject } from '@kbn/ml-is-populated-object';
import type { TimeRange as TimeRangeMs } from '@kbn/ml-date-picker';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { isRuntimeMappings } from '../../../../../../common/util/runtime_field_utils';
import { RuntimeMappings } from '../../../../../../common/types/fields';
import { DEFAULT_SAMPLER_SHARD_SIZE } from '../../../../../../common/constants/field_histograms';
@ -34,7 +36,7 @@ import {
getProcessedFields,
getCombinedRuntimeMappings,
} from '../../../../components/data_grid';
import { extractErrorMessage } from '../../../../../../common/util/errors';
import { INDEX_STATUS } from '../../../common/analytics';
import { ml } from '../../../../services/ml_api_service';

View file

@ -6,17 +6,19 @@
*/
import React, { FC, useEffect, useMemo, useState } from 'react';
import { EuiButtonGroup, EuiCode, EuiFlexGroup, EuiFlexItem, EuiInputPopover } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { debounce } from 'lodash';
import { fromKueryExpression, luceneStringToDsl, toElasticsearchQuery } from '@kbn/es-query';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { EuiButtonGroup, EuiCode, EuiFlexGroup, EuiFlexItem, EuiInputPopover } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { fromKueryExpression, luceneStringToDsl, toElasticsearchQuery } from '@kbn/es-query';
import { DataView } from '@kbn/data-views-plugin/common';
import type { Query } from '@kbn/es-query';
import { QueryStringInput } from '@kbn/unified-search-plugin/public';
import { Dictionary } from '../../../../../../../common/types/common';
import { QueryErrorMessage } from '@kbn/ml-error-utils';
import { Dictionary } from '../../../../../../../common/types/common';
import {
SEARCH_QUERY_LANGUAGE,
SearchQueryLanguage,
@ -25,11 +27,6 @@ import { removeFilterFromQueryString } from '../../../../../explorer/explorer_ut
import { SavedSearchQuery } from '../../../../../contexts/ml';
import { useMlKibana } from '../../../../../contexts/kibana';
interface ErrorMessage {
query: string;
message: string;
}
export interface ExplorationQueryBarProps {
indexPattern: DataView;
setSearchQuery: (update: {
@ -55,7 +52,9 @@ export const ExplorationQueryBar: FC<ExplorationQueryBarProps> = ({
// The internal state of the input query bar updated on every key stroke.
const [searchInput, setSearchInput] = useState<Query>(query);
const [idToSelectedMap, setIdToSelectedMap] = useState<{ [id: string]: boolean }>({});
const [errorMessage, setErrorMessage] = useState<ErrorMessage | undefined>(undefined);
const [queryErrorMessage, setQueryErrorMessage] = useState<QueryErrorMessage | undefined>(
undefined
);
const { services } = useMlKibana();
const {
@ -119,7 +118,7 @@ export const ExplorationQueryBar: FC<ExplorationQueryBarProps> = ({
convertedQuery = luceneStringToDsl(query.query as string);
break;
default:
setErrorMessage({
setQueryErrorMessage({
query: query.query as string,
message: i18n.translate('xpack.ml.queryBar.queryLanguageNotSupported', {
defaultMessage: 'Query language is not supported',
@ -133,7 +132,7 @@ export const ExplorationQueryBar: FC<ExplorationQueryBarProps> = ({
language: query.language,
});
} catch (e) {
setErrorMessage({ query: query.query as string, message: e.message });
setQueryErrorMessage({ query: query.query as string, message: e.message });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [query.query]);
@ -187,7 +186,7 @@ export const ExplorationQueryBar: FC<ExplorationQueryBarProps> = ({
return (
<EuiInputPopover
style={{ maxWidth: '100%' }}
closePopover={() => setErrorMessage(undefined)}
closePopover={() => setQueryErrorMessage(undefined)}
input={
<EuiFlexGroup alignItems="center">
<EuiFlexItem>
@ -249,14 +248,14 @@ export const ExplorationQueryBar: FC<ExplorationQueryBarProps> = ({
)}
</EuiFlexGroup>
}
isOpen={errorMessage?.query === searchInput.query && errorMessage?.message !== ''}
isOpen={queryErrorMessage?.query === searchInput.query && queryErrorMessage?.message !== ''}
>
<EuiCode>
{i18n.translate('xpack.ml.stepDefineForm.invalidQuery', {
defaultMessage: 'Invalid Query',
})}
{': '}
{errorMessage?.message.split('\n')[0]}
{queryErrorMessage?.message.split('\n')[0]}
</EuiCode>
</EuiInputPopover>
);

View file

@ -10,9 +10,10 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
import { EuiDataGridColumn } from '@elastic/eui';
import { CoreSetup } from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import type { DataView } from '@kbn/data-views-plugin/public';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { MlApiServices } from '../../../../../services/ml_api_service';
import { DataLoader } from '../../../../../datavisualizer/index_based/data_loader';
@ -35,7 +36,6 @@ import { FEATURE_IMPORTANCE, TOP_CLASSES } from '../../../../common/constants';
import { DEFAULT_RESULTS_FIELD } from '../../../../../../../common/constants/data_frame_analytics';
import { sortExplorationResultsFields, ML__ID_COPY } from '../../../../common/fields';
import { isRegressionAnalysis } from '../../../../common/analytics';
import { extractErrorMessage } from '../../../../../../../common/util/errors';
import { useTrainedModelsApiService } from '../../../../../services/ml_api_service/trained_models';
import { FeatureImportanceBaseline } from '../../../../../../../common/types/feature_importance';
import { useExplorationDataGrid } from './use_exploration_data_grid';

View file

@ -11,6 +11,7 @@ import { cloneDeep, isEqual } from 'lodash';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { toMountPoint, wrapWithTheme } from '@kbn/kibana-react-plugin/public';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { DeepReadonly } from '../../../../../../../common/types/common';
import { DataFrameAnalyticsConfig, isOutlierAnalysis } from '../../../../common';
import { isClassificationAnalysis, isRegressionAnalysis } from '../../../../common/analytics';
@ -19,7 +20,6 @@ import { useMlKibana, useNavigateToPath } from '../../../../../contexts/kibana';
import { DEFAULT_NUM_TOP_FEATURE_IMPORTANCE_VALUES } from '../../hooks/use_create_analytics_form';
import { State } from '../../hooks/use_create_analytics_form/state';
import { DataFrameAnalyticsListRow } from '../analytics_list/common';
import { extractErrorMessage } from '../../../../../../../common/util/errors';
interface PropDefinition {
/**

View file

@ -8,7 +8,7 @@
import React, { useEffect, useMemo, useState } from 'react';
import { i18n } from '@kbn/i18n';
import { extractErrorMessage } from '../../../../../../../common/util/errors';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { useMlKibana } from '../../../../../contexts/kibana';
import { useToastNotificationService } from '../../../../../services/toast_notification_service';

View file

@ -10,7 +10,8 @@ import { useReducer } from 'react';
import { i18n } from '@kbn/i18n';
import { DuplicateDataViewError } from '@kbn/data-plugin/public';
import { extractErrorMessage } from '../../../../../../../common/util/errors';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { DeepReadonly } from '../../../../../../../common/types/common';
import { ml } from '../../../../../services/ml_api_service';
import { useMlContext } from '../../../../../contexts/ml';

View file

@ -6,7 +6,8 @@
*/
import { i18n } from '@kbn/i18n';
import { extractErrorMessage } from '../../../../../../../common/util/errors';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { ml } from '../../../../../services/ml_api_service';
import { ToastNotificationService } from '../../../../../services/toast_notification_service';
import { refreshAnalyticsList$, REFRESH_ANALYTICS_LIST_STATE } from '../../../../common';

View file

@ -12,7 +12,8 @@ import { fromKueryExpression, luceneStringToDsl, toElasticsearchQuery } from '@k
import type { Query } from '@kbn/es-query';
import { QueryStringInput } from '@kbn/unified-search-plugin/public';
import type { DataView } from '@kbn/data-views-plugin/common';
import { SEARCH_QUERY_LANGUAGE, ErrorMessage } from '../../../../../common/constants/search';
import type { QueryErrorMessage } from '@kbn/ml-error-utils';
import { SEARCH_QUERY_LANGUAGE } from '../../../../../common/constants/search';
import { InfluencersFilterQuery } from '../../../../../common/types/es_client';
import { useAnomalyExplorerContext } from '../../anomaly_explorer_context';
import { useMlKibana } from '../../../contexts/kibana';
@ -129,7 +130,9 @@ export const ExplorerQueryBar: FC<ExplorerQueryBarProps> = ({
const [searchInput, setSearchInput] = useState<Query>(
getInitSearchInputState({ filterActive, queryString })
);
const [errorMessage, setErrorMessage] = useState<ErrorMessage | undefined>(undefined);
const [queryErrorMessage, setQueryErrorMessage] = useState<QueryErrorMessage | undefined>(
undefined
);
useEffect(
function updateSearchInputFromFilter() {
@ -160,14 +163,14 @@ export const ExplorerQueryBar: FC<ExplorerQueryBarProps> = ({
}
} catch (e) {
console.log('Invalid query syntax in search bar', e); // eslint-disable-line no-console
setErrorMessage({ query: query.query as string, message: e.message });
setQueryErrorMessage({ query: query.query as string, message: e.message });
}
};
return (
<EuiInputPopover
css={{ 'max-width': '100%' }}
closePopover={setErrorMessage.bind(null, undefined)}
closePopover={setQueryErrorMessage.bind(null, undefined)}
input={
<QueryStringInput
bubbleSubmitEvent={false}
@ -192,14 +195,14 @@ export const ExplorerQueryBar: FC<ExplorerQueryBarProps> = ({
}}
/>
}
isOpen={errorMessage?.query === searchInput.query && errorMessage?.message !== ''}
isOpen={queryErrorMessage?.query === searchInput.query && queryErrorMessage?.message !== ''}
>
<EuiCode>
{i18n.translate('xpack.ml.explorer.invalidKuerySyntaxErrorMessageQueryBar', {
defaultMessage: 'Invalid query',
})}
{': '}
{errorMessage?.message.split('\n')[0]}
{queryErrorMessage?.message.split('\n')[0]}
</EuiCode>
</EuiInputPopover>
);

View file

@ -11,19 +11,20 @@
import { get, union, uniq } from 'lodash';
import moment from 'moment-timezone';
import { lastValueFrom } from 'rxjs';
import { ES_FIELD_TYPES } from '@kbn/field-types';
import { asyncForEach } from '@kbn/std';
import { isPopulatedObject } from '@kbn/ml-is-populated-object';
import type { DataViewsContract } from '@kbn/data-views-plugin/public';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { lastValueFrom } from 'rxjs';
import {
ANNOTATIONS_TABLE_DEFAULT_QUERY_SIZE,
ANOMALIES_TABLE_DEFAULT_QUERY_SIZE,
} from '../../../common/constants/search';
import { EntityField, getEntityFieldList } from '../../../common/util/anomaly_utils';
import { getDataViewIdFromName } from '../util/index_utils';
import { extractErrorMessage } from '../../../common/util/errors';
import { ML_JOB_AGGREGATION } from '../../../common/constants/aggregation_types';
import {
isSourceDataChartableForDetector,

View file

@ -9,10 +9,10 @@ import React, { FC, useCallback, useEffect, useState } from 'react';
import { EuiButton, EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiToolTip } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { ml } from '../../../../services/ml_api_service';
import { JobMessages } from '../../../../components/job_messages';
import { JobMessage } from '../../../../../../common/types/audit_message';
import { extractErrorMessage } from '../../../../../../common/util/errors';
import { useToastNotificationService } from '../../../../services/toast_notification_service';
import { useMlApiContext } from '../../../../contexts/kibana';
import { checkPermission } from '../../../../capabilities/check_capabilities';

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import { i18n } from '@kbn/i18n';
import { combineLatest, Observable, of, Subject, Subscription } from 'rxjs';
import { isEqual, cloneDeep } from 'lodash';
import {
@ -21,10 +20,13 @@ import {
skipWhile,
} from 'rxjs/operators';
import { useEffect, useMemo } from 'react';
import { i18n } from '@kbn/i18n';
import { type MLHttpFetchError, extractErrorMessage } from '@kbn/ml-error-utils';
import { DEFAULT_MODEL_MEMORY_LIMIT } from '../../../../../../../common/constants/new_job';
import { ml } from '../../../../../services/ml_api_service';
import { JobValidator, VALIDATION_DELAY_MS } from '../../job_validator/job_validator';
import { MLHttpFetchError, extractErrorMessage } from '../../../../../../../common/util/errors';
import { useMlKibana } from '../../../../../contexts/kibana';
import { JobCreator } from '../job_creator';

View file

@ -17,9 +17,9 @@ import type { Filter, Query, DataViewBase } from '@kbn/es-query';
import { FilterStateStore } from '@kbn/es-query';
import type { Embeddable } from '@kbn/lens-plugin/public';
import type { MapEmbeddable } from '@kbn/maps-plugin/public';
import type { ErrorType } from '@kbn/ml-error-utils';
import type { MlApiServices } from '../../../services/ml_api_service';
import { getFiltersForDSLQuery } from '../../../../../common/util/job_utils';
import type { ErrorType } from '../../../../../common/util/errors';
import { CREATED_BY_LABEL } from '../../../../../common/constants/new_job';
import { createQueries } from '../utils/new_job_utils';
import { createDatafeedId } from '../../../../../common/util/job_utils';

View file

@ -10,8 +10,8 @@ import { layerTypes } from '@kbn/lens-plugin/public';
import { i18n } from '@kbn/i18n';
import type { ErrorType } from '@kbn/ml-error-utils';
import { JOB_TYPE } from '../../../../../common/constants/new_job';
import { ErrorType } from '../../../../../common/util/errors';
import {
getVisTypeFactory,
isCompatibleLayer,

View file

@ -6,7 +6,6 @@
*/
import React, { FC, useState, useEffect, useCallback, useContext } from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
import {
@ -23,7 +22,10 @@ import {
EuiModalBody,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { SavedObjectFinder } from '@kbn/saved-objects-finder-plugin/public';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { JobCreatorContext } from '../../../job_creator_context';
import { AdvancedJobCreator } from '../../../../../common/job_creator';
import { resetAdvancedJob } from '../../../../../common/job_creator/util/general';
@ -31,7 +33,6 @@ import {
CombinedJob,
Datafeed,
} from '../../../../../../../../../common/types/anomaly_detection_jobs';
import { extractErrorMessage } from '../../../../../../../../../common/util/errors';
import type { DatafeedValidationResponse } from '../../../../../../../../../common/types/job_validation';
import {

View file

@ -11,10 +11,10 @@ import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
import { from } from 'rxjs';
import { switchMap, takeWhile, tap } from 'rxjs/operators';
import { extractErrorProperties } from '@kbn/ml-error-utils';
import { JobCreatorContext } from '../../../job_creator_context';
import { CategorizationJobCreator } from '../../../../../common/job_creator';
import { ml } from '../../../../../../../services/ml_api_service';
import { extractErrorProperties } from '../../../../../../../../../common/util/errors';
const NUMBER_OF_PREVIEW = 5;
export const CategoryStoppedPartitions: FC = () => {

View file

@ -8,13 +8,13 @@
import React, { FC, useContext, useEffect, useState } from 'react';
import { EuiBasicTable, EuiText } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { extractErrorProperties } from '@kbn/ml-error-utils';
import { JobCreatorContext } from '../../../job_creator_context';
import { CategorizationJobCreator } from '../../../../../common/job_creator';
import { Results } from '../../../../../common/results_loader';
import { ml } from '../../../../../../../services/ml_api_service';
import { useToastNotificationService } from '../../../../../../../services/toast_notification_service';
import { NUMBER_OF_CATEGORY_EXAMPLES } from '../../../../../../../../../common/constants/categorization_job';
import { extractErrorProperties } from '../../../../../../../../../common/util/errors';
export const TopCategories: FC = () => {
const { displayErrorToast } = useToastNotificationService();

View file

@ -6,12 +6,15 @@
*/
import React, { FC, Fragment, useContext, useState } from 'react';
import { EuiButton, EuiFlexItem } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { JobRunner } from '../../../../../common/job_runner';
import { useMlKibana } from '../../../../../../../contexts/kibana';
import { extractErrorMessage } from '../../../../../../../../../common/util/errors';
import { JobCreatorContext } from '../../../job_creator_context';
import { DATAFEED_STATE } from '../../../../../../../../../common/constants/states';

View file

@ -18,11 +18,11 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { ModuleJobUI } from '../page';
import { SETUP_RESULTS_WIDTH } from './module_jobs';
import { tabColor } from '../../../../../../common/util/group_color_utils';
import { JobOverride, DatafeedResponse } from '../../../../../../common/types/modules';
import { extractErrorMessage } from '../../../../../../common/util/errors';
interface JobItemProps {
job: ModuleJobUI;

View file

@ -18,8 +18,8 @@ import {
EuiSpacer,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { KibanaObjectUi } from '../page';
import { extractErrorMessage } from '../../../../../../common/util/errors';
export interface KibanaObjectItemProps {
objectType: string;

View file

@ -11,7 +11,7 @@ import { i18n } from '@kbn/i18n';
import { map } from 'rxjs/operators';
import { SupportedPytorchTasksType } from '@kbn/ml-trained-models-utils';
import { MLHttpFetchError } from '../../../../../common/util/errors';
import type { MLHttpFetchError } from '@kbn/ml-error-utils';
import { trainedModelsApiProvider } from '../../../services/ml_api_service/trained_models';
import { getInferenceInfoComponent } from './inference_info';

View file

@ -8,7 +8,7 @@
import React, { FC, useState, useMemo, useCallback, FormEventHandler } from 'react';
import useObservable from 'react-use/lib/useObservable';
import { FormattedMessage } from '@kbn/i18n-react';
import {
EuiSpacer,
EuiButton,
@ -21,8 +21,10 @@ import {
EuiForm,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { ErrorMessage } from '../../inference_error';
import { extractErrorMessage } from '../../../../../../common';
import type { InferrerType } from '..';
import { useIndexInput, InferenceInputFormIndexControls } from '../index_input';
import { RUNNING_STATE } from '../inference_base';

View file

@ -6,13 +6,14 @@
*/
import React, { FC, useState, useMemo, useCallback, FormEventHandler } from 'react';
import useObservable from 'react-use/lib/useObservable';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiSpacer, EuiButton, EuiTabs, EuiTab, EuiForm } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { ErrorMessage } from '../../inference_error';
import { extractErrorMessage } from '../../../../../../common';
import type { InferrerType } from '..';
import { OutputLoadingContent } from '../../output_loading';
import { RUNNING_STATE } from '../inference_base';

View file

@ -16,6 +16,7 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { each, get } from 'lodash';
import { isPopulatedObject } from '@kbn/ml-is-populated-object';
import type { ErrorType } from '@kbn/ml-error-utils';
import { Dictionary } from '../../../../common/types/common';
import { ML_MEDIAN_PERCENTS } from '../../../../common/util/job_utils';
import { Datafeed, JobId } from '../../../../common/types/anomaly_detection_jobs';
@ -28,7 +29,6 @@ import { ES_AGGREGATION } from '../../../../common/constants/aggregation_types';
import { InfluencersFilterQuery } from '../../../../common/types/es_client';
import { RecordForInfluencer } from './results_service';
import { isRuntimeMappings } from '../../../../common';
import { ErrorType } from '../../../../common/util/errors';
export interface ResultResponse {
success: boolean;

View file

@ -8,13 +8,9 @@
import { i18n } from '@kbn/i18n';
import { ToastInput, ToastOptions, ToastsStart } from '@kbn/core/public';
import { useMemo } from 'react';
import { extractErrorProperties, type ErrorType, MLRequestFailure } from '@kbn/ml-error-utils';
import { getToastNotifications } from '../../util/dependency_cache';
import { useNotifications } from '../../contexts/kibana';
import {
ErrorType,
extractErrorProperties,
MLRequestFailure,
} from '../../../../common/util/errors';
export type ToastNotificationService = ReturnType<typeof toastNotificationServiceProvider>;

View file

@ -5,10 +5,11 @@
* 2.0.
*/
import { i18n } from '@kbn/i18n';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { getToastNotifications } from '../../../util/dependency_cache';
import { ml } from '../../../services/ml_api_service';
import { i18n } from '@kbn/i18n';
import { extractErrorMessage } from '../../../../../common/util/errors';
export async function deleteCalendars(calendarsToDelete, callback) {
if (calendarsToDelete === undefined || calendarsToDelete.length === 0) {

View file

@ -16,9 +16,13 @@ import React, { Component } from 'react';
import { EuiButton, EuiToolTip } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { withKibana } from '@kbn/kibana-react-plugin/public';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { FORECAST_REQUEST_STATE, JOB_STATE } from '../../../../../common/constants/states';
import { MESSAGE_LEVEL } from '../../../../../common/constants/message_levels';
import { extractErrorMessage } from '../../../../../common/util/errors';
import { isJobVersionGte } from '../../../../../common/util/job_utils';
import { parseInterval } from '../../../../../common/util/parse_interval';
import { Modal } from './modal';
@ -26,9 +30,6 @@ import { PROGRESS_STATES } from './progress_states';
import { ml } from '../../../services/ml_api_service';
import { mlJobService } from '../../../services/job_service';
import { mlForecastService } from '../../../services/forecast_service';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { withKibana } from '@kbn/kibana-react-plugin/public';
export const FORECAST_DURATION_MAX_DAYS = 3650; // Max forecast duration allowed by analytics.

View file

@ -7,11 +7,11 @@
import React, { FC, useEffect, useState, useCallback, useContext } from 'react';
import { i18n } from '@kbn/i18n';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { MlTooltipComponent } from '../../../components/chart_tooltip';
import { TimeseriesChart } from './timeseries_chart';
import { CombinedJob } from '../../../../../common/types/anomaly_detection_jobs';
import { ANNOTATIONS_TABLE_DEFAULT_QUERY_SIZE } from '../../../../../common/constants/search';
import { extractErrorMessage } from '../../../../../common/util/errors';
import { Annotation } from '../../../../../common/types/annotations';
import { useMlKibana, useNotifications } from '../../../contexts/kibana';
import { getBoundsRoundedToInterval } from '../../../util/time_buckets';

View file

@ -7,9 +7,9 @@
import { forkJoin, Observable, of } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { ml } from '../../services/ml_api_service';
import { ANNOTATIONS_TABLE_DEFAULT_QUERY_SIZE } from '../../../../common/constants/search';
import { extractErrorMessage } from '../../../../common/util/errors';
import { mlTimeSeriesSearchService } from '../timeseries_search_service';
import { mlResultsService, CriteriaField } from '../../services/results_service';
import { Job } from '../../../../common/types/anomaly_detection_jobs';

View file

@ -5,14 +5,10 @@
* 2.0.
*/
import { i18n } from '@kbn/i18n';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import React, { FC, useState, useCallback } from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import useDebounce from 'react-use/lib/useDebounce';
import type { Embeddable } from '@kbn/lens-plugin/public';
import type { MapEmbeddable } from '@kbn/maps-plugin/public';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import {
EuiFlexGroup,
EuiFlexItem,
@ -30,11 +26,16 @@ import {
EuiCallOut,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import type { Embeddable } from '@kbn/lens-plugin/public';
import type { MapEmbeddable } from '@kbn/maps-plugin/public';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { QuickLensJobCreator } from '../../../application/jobs/new_job/job_from_lens';
import type { LayerResult } from '../../../application/jobs/new_job/job_from_lens';
import type { CreateState } from '../../../application/jobs/new_job/job_from_dashboard';
import { JOB_TYPE, DEFAULT_BUCKET_SPAN } from '../../../../common/constants/new_job';
import { extractErrorMessage } from '../../../../common/util/errors';
import { basicJobValidation } from '../../../../common/util/job_utils';
import { JOB_ID_MAX_LENGTH } from '../../../../common/constants/validation';
import { invalidTimeIntervalMessage } from '../../../application/jobs/new_job/common/job_validator/util';

View file

@ -6,13 +6,13 @@
*/
import React, { FC } from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiFlexGroup, EuiFlexItem, EuiIcon, EuiText } from '@elastic/eui';
import type { LayerResult } from '../../../../../application/jobs/new_job/job_from_lens';
import { FormattedMessage } from '@kbn/i18n-react';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { extractErrorMessage } from '../../../../../../common/util/errors';
import type { LayerResult } from '../../../../../application/jobs/new_job/job_from_lens';
interface Props {
layer: LayerResult;

View file

@ -15,7 +15,6 @@ export * from '../common/types/modules';
export * from '../common/types/audit_message';
export * from '../common/util/anomaly_utils';
export * from '../common/util/errors';
export * from '../common/util/validators';
export * from '../common/util/date_utils';

View file

@ -8,6 +8,7 @@
import { i18n } from '@kbn/i18n';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { IScopedClusterClient } from '@kbn/core/server';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { getAnalysisType } from '../../../common/util/analytics_utils';
import { ANALYSIS_CONFIG_TYPE } from '../../../common/constants/data_frame_analytics';
import {
@ -25,7 +26,6 @@ import {
isRegressionAnalysis,
isClassificationAnalysis,
} from '../../../common/util/analytics_utils';
import { extractErrorMessage } from '../../../common/util/errors';
import {
AnalysisConfig,
DataFrameAnalyticsConfig,

View file

@ -30,7 +30,6 @@
"@kbn/charts-plugin",
"@kbn/cloud-plugin",
"@kbn/config-schema",
"@kbn/core-http-browser",
"@kbn/dashboard-plugin",
"@kbn/data-plugin",
"@kbn/data-views-plugin",
@ -90,5 +89,6 @@
"@kbn/unified-search-plugin",
"@kbn/usage-collection-plugin",
"@kbn/utility-types",
"@kbn/ml-error-utils",
],
}

View file

@ -11,7 +11,7 @@ import {
JobExistResult,
MlCapabilitiesResponse,
} from '@kbn/ml-plugin/public';
import { extractErrorMessage } from '@kbn/ml-plugin/common';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import { apiService } from './utils';
import { AnomalyRecords, AnomalyRecordsParams } from '../actions';
import { API_URLS, ML_MODULE_ID } from '../../../../common/constants';

View file

@ -78,6 +78,7 @@
"@kbn/alerts-as-data-utils",
"@kbn/exploratory-view-plugin",
"@kbn/observability-shared-plugin",
"@kbn/ml-error-utils",
],
"exclude": [
"target/**/*",

View file

@ -8,6 +8,7 @@
import React, { useCallback, useEffect, useState } from 'react';
import { i18n } from '@kbn/i18n';
import { toMountPoint } from '@kbn/kibana-react-plugin/public';
import { extractErrorMessage } from '@kbn/ml-error-utils';
import type {
DeleteTransformStatus,
DeleteTransformsRequestSchema,
@ -24,7 +25,6 @@ export const useDeleteIndexAndTargetIndex = (items: TransformListRow[]) => {
const {
http,
data: { dataViews: dataViewsContract },
ml: { extractErrorMessage },
application: { capabilities },
} = useAppDependencies();
const toastNotifications = useToastNotifications();
@ -62,7 +62,7 @@ export const useDeleteIndexAndTargetIndex = (items: TransformListRow[]) => {
);
}
},
[dataViewsContract, toastNotifications, extractErrorMessage]
[dataViewsContract, toastNotifications]
);
const checkUserIndexPermission = useCallback(async () => {

View file

@ -25,8 +25,8 @@ interface SourceSearchBarProps {
}
export const SourceSearchBar: FC<SourceSearchBarProps> = ({ dataView, searchBar }) => {
const {
actions: { searchChangeHandler, searchSubmitHandler, setErrorMessage },
state: { errorMessage, searchInput },
actions: { searchChangeHandler, searchSubmitHandler, setQueryErrorMessage },
state: { queryErrorMessage, searchInput },
} = searchBar;
const {
@ -44,7 +44,7 @@ export const SourceSearchBar: FC<SourceSearchBarProps> = ({ dataView, searchBar
return (
<EuiInputPopover
style={{ maxWidth: '100%' }}
closePopover={() => setErrorMessage(undefined)}
closePopover={() => setQueryErrorMessage(undefined)}
input={
<QueryStringInput
bubbleSubmitEvent={true}
@ -80,13 +80,13 @@ export const SourceSearchBar: FC<SourceSearchBarProps> = ({ dataView, searchBar
}}
/>
}
isOpen={errorMessage?.query === searchInput.query && errorMessage?.message !== ''}
isOpen={queryErrorMessage?.query === searchInput.query && queryErrorMessage?.message !== ''}
>
<EuiCode>
{i18n.translate('xpack.transform.stepDefineForm.invalidKuerySyntaxErrorMessageQueryBar', {
defaultMessage: 'Invalid query: {errorMessage}',
defaultMessage: 'Invalid query: {queryErrorMessage}',
values: {
errorMessage: errorMessage?.message.split('\n')[0],
queryErrorMessage: queryErrorMessage?.message.split('\n')[0],
},
})}
</EuiCode>

View file

@ -13,4 +13,4 @@ export { getDefaultAggregationConfig } from './get_default_aggregation_config';
export { getDefaultGroupByConfig } from './get_default_group_by_config';
export { getDefaultStepDefineState } from './get_default_step_define_state';
export { getPivotDropdownOptions } from './get_pivot_dropdown_options';
export type { ErrorMessage, Field, StepDefineExposedState } from './types';
export type { Field, StepDefineExposedState } from './types';

View file

@ -28,11 +28,6 @@ import {
import { LatestFunctionConfig } from '../../../../../../../common/api_schemas/transforms';
import { RUNTIME_FIELD_TYPES } from '../../../../../../../common/shared_imports';
export interface ErrorMessage {
query: string;
message: string;
}
export interface Field {
name: EsFieldName;
type: KBN_FIELD_TYPES | TIME_SERIES_METRIC_TYPES.COUNTER;

View file

@ -9,11 +9,11 @@ import { useState } from 'react';
import { toElasticsearchQuery, fromKueryExpression, luceneStringToDsl } from '@kbn/es-query';
import type { Query } from '@kbn/es-query';
import type { QueryErrorMessage } from '@kbn/ml-error-utils';
import { getTransformConfigQuery } from '../../../../../common';
import {
ErrorMessage,
StepDefineExposedState,
QUERY_LANGUAGE_KUERY,
QUERY_LANGUAGE_LUCENE,
@ -43,7 +43,9 @@ export const useSearchBar = (
const [searchQuery, setSearchQuery] = useState(defaults.searchQuery);
const [errorMessage, setErrorMessage] = useState<ErrorMessage | undefined>(undefined);
const [queryErrorMessage, setQueryErrorMessage] = useState<QueryErrorMessage | undefined>(
undefined
);
const searchChangeHandler = (query: Query) => setSearchInput(query);
const searchSubmitHandler = (query: Query) => {
@ -61,7 +63,7 @@ export const useSearchBar = (
return;
}
} catch (e) {
setErrorMessage({ query: query.query as string, message: e.message });
setQueryErrorMessage({ query: query.query as string, message: e.message });
}
};
@ -71,14 +73,14 @@ export const useSearchBar = (
actions: {
searchChangeHandler,
searchSubmitHandler,
setErrorMessage,
setQueryErrorMessage,
setSearchInput,
setSearchLanguage,
setSearchQuery,
setSearchString,
},
state: {
errorMessage,
queryErrorMessage,
transformConfigQuery,
searchInput,
searchLanguage,

View file

@ -142,7 +142,7 @@ export function wrapEsError(err: any, statusCodeToMessageMap: Record<string, any
// Set error message based on the root cause
if (root_cause?.[0]) {
boomError.message = extractErrorMessage(root_cause[0]);
boomError.message = extractErrorMessageBasedOnRootCause(root_cause[0]);
}
return boomError;
@ -165,7 +165,7 @@ interface EsError {
/**
* Returns an error message based on the root cause
*/
function extractErrorMessage({ type, reason, script, line, col }: EsError): string {
function extractErrorMessageBasedOnRootCause({ type, reason, script, line, col }: EsError): string {
let message = `[${type}] ${reason}`;
if (line !== undefined && col !== undefined) {

View file

@ -58,7 +58,8 @@
"@kbn/saved-objects-finder-plugin",
"@kbn/ml-route-utils",
"@kbn/core-lifecycle-server",
"@kbn/security-plugin"
"@kbn/security-plugin",
"@kbn/ml-error-utils"
],
"exclude": [
"target/**/*",

View file

@ -35553,7 +35553,7 @@
"xpack.transform.stepCreateForm.duplicateDataViewErrorMessage": "Une erreur est survenue lors de la création de la vue de données Kibana {dataViewName} : La vue de données existe déjà.",
"xpack.transform.stepCreateForm.startTransformErrorMessage": "Une erreur s'est produite lors du démarrage de la transformation {transformId} :",
"xpack.transform.stepCreateForm.startTransformSuccessMessage": "La requête pour démarrer la transformation {transformId} a été reconnue.",
"xpack.transform.stepDefineForm.invalidKuerySyntaxErrorMessageQueryBar": "Requête non valide : {errorMessage}",
"xpack.transform.stepDefineForm.invalidKuerySyntaxErrorMessageQueryBar": "Requête non valide : {queryErrorMessage}",
"xpack.transform.stepDefineForm.queryPlaceholderKql": "Par exemple, {example}",
"xpack.transform.stepDefineForm.queryPlaceholderLucene": "Par exemple, {example}",
"xpack.transform.stepDefineForm.runtimeFieldsListLabel": "{runtimeFields}",

View file

@ -35532,7 +35532,7 @@
"xpack.transform.stepCreateForm.duplicateDataViewErrorMessage": "Kibanaデータビュー{dataViewName}の作成中にエラーが発生しました:データビューはすでに存在します。",
"xpack.transform.stepCreateForm.startTransformErrorMessage": "変換 {transformId} の開始中にエラーが発生しました。",
"xpack.transform.stepCreateForm.startTransformSuccessMessage": "変換 {transformId} の開始リクエストが受け付けられました。",
"xpack.transform.stepDefineForm.invalidKuerySyntaxErrorMessageQueryBar": "無効なクエリ:{errorMessage}",
"xpack.transform.stepDefineForm.invalidKuerySyntaxErrorMessageQueryBar": "無効なクエリ:{queryErrorMessage}",
"xpack.transform.stepDefineForm.queryPlaceholderKql": "例: {example}.",
"xpack.transform.stepDefineForm.queryPlaceholderLucene": "例: {example}.",
"xpack.transform.stepDefineForm.runtimeFieldsListLabel": "{runtimeFields}",

View file

@ -35548,7 +35548,7 @@
"xpack.transform.stepCreateForm.duplicateDataViewErrorMessage": "创建 Kibana 数据视图 {dataViewName} 时发生错误:数据视图已存在。",
"xpack.transform.stepCreateForm.startTransformErrorMessage": "启动转换 {transformId} 时发生错误:",
"xpack.transform.stepCreateForm.startTransformSuccessMessage": "启动转换 {transformId} 的请求已确认。",
"xpack.transform.stepDefineForm.invalidKuerySyntaxErrorMessageQueryBar": "无效查询:{errorMessage}",
"xpack.transform.stepDefineForm.invalidKuerySyntaxErrorMessageQueryBar": "无效查询:{queryErrorMessage}",
"xpack.transform.stepDefineForm.queryPlaceholderKql": "例如,{example}",
"xpack.transform.stepDefineForm.queryPlaceholderLucene": "例如,{example}",
"xpack.transform.stepDefineForm.runtimeFieldsListLabel": "{runtimeFields}",

View file

@ -4545,6 +4545,10 @@
version "0.0.0"
uid ""
"@kbn/ml-error-utils@link:x-pack/packages/ml/error_utils":
version "0.0.0"
uid ""
"@kbn/ml-is-defined@link:x-pack/packages/ml/is_defined":
version "0.0.0"
uid ""