From 43f5dd5f64065c618ba930b2a4087f0a9e706c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20=C3=81ngel?= Date: Wed, 29 May 2019 12:36:20 +0200 Subject: [PATCH] Import "getPainlessError" function from Kibana --- .../kibana-integrations/get_painless_error.ts | 51 +++++++++++++++++++ public/kibana-integrations/kibana-discover.js | 2 + 2 files changed, 53 insertions(+) create mode 100644 public/kibana-integrations/get_painless_error.ts diff --git a/public/kibana-integrations/get_painless_error.ts b/public/kibana-integrations/get_painless_error.ts new file mode 100644 index 0000000000..03ca50a994 --- /dev/null +++ b/public/kibana-integrations/get_painless_error.ts @@ -0,0 +1,51 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { i18n } from '@kbn/i18n'; +import { get } from 'lodash'; + +export function getPainlessError(error: Error) { + const rootCause: Array<{ lang: string; script: string }> | undefined = get( + error, + 'resp.error.root_cause' + ); + + if (!rootCause) { + return; + } + + const [{ lang, script }] = rootCause; + + if (lang !== 'painless') { + return; + } + + return { + lang, + script, + message: i18n.translate( + 'kbn.discover.painlessError.painlessScriptedFieldErrorMessage', + { + defaultMessage: "Error with Painless scripted field '{script}'.", + values: { script } + } + ), + error: error.message + }; +} diff --git a/public/kibana-integrations/kibana-discover.js b/public/kibana-integrations/kibana-discover.js index 2d1b3634d4..5d311e12ae 100644 --- a/public/kibana-integrations/kibana-discover.js +++ b/public/kibana-integrations/kibana-discover.js @@ -99,6 +99,8 @@ import { buildVislibDimensions } from 'ui/visualize/loader/pipeline_helpers/buil import 'ui/courier/search_strategy/default_search_strategy'; +import { getPainlessError } from './get_painless_error'; + const app = uiModules.get('apps/discover', [ 'kibana/notify', 'kibana/courier',