Moved KbnError base class ⇒ kibana_utils (#45532) (#45809)

* moved errors base class to kibana_utils

* Fixed tests for ui/errors imports

* fixed test path

* Restored Request Failure resp field

* Restored savedObjectType and savedObjectId

* simplified Error class extension

* updated constructors
This commit is contained in:
Liza Katz 2019-09-17 11:33:15 +03:00 committed by GitHub
parent d79449ec55
commit 273bba5112
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 245 additions and 382 deletions

View file

@ -18,7 +18,7 @@
*/
import _ from 'lodash';
import { SavedObjectNotFound } from 'ui/errors';
import { SavedObjectNotFound } from '../../../../../../../plugins/kibana_utils/public';
function getParams(filter, indexPattern) {
const type = 'geo_bounding_box';

View file

@ -18,7 +18,7 @@
*/
import _ from 'lodash';
import { SavedObjectNotFound } from 'ui/errors';
import { SavedObjectNotFound } from '../../../../../../../plugins/kibana_utils/public';
function getParams(filter, indexPattern) {
const type = 'geo_polygon';

View file

@ -18,7 +18,7 @@
*/
import _ from 'lodash';
import { SavedObjectNotFound } from 'ui/errors';
import { SavedObjectNotFound } from '../../../../../../../plugins/kibana_utils/public';
function isScriptedPhrase(filter) {
const value = _.get(filter, ['script', 'script', 'params', 'value']);

View file

@ -18,7 +18,7 @@
*/
import { has, get } from 'lodash';
import { SavedObjectNotFound } from 'ui/errors';
import { SavedObjectNotFound } from '../../../../../../../plugins/kibana_utils/public';
function isScriptedRange(filter) {

View file

@ -19,8 +19,7 @@
/* eslint-disable */
// @ts-ignore
import { KbnError } from 'ui/errors';
import { KbnError } from '../../../../../plugins/kibana_utils/public';
/**
* when a mapping already exists for a field the user is attempting to add
@ -28,7 +27,7 @@ import { KbnError } from 'ui/errors';
*/
export class IndexPatternAlreadyExists extends KbnError {
constructor(name: string) {
super(`An index pattern of "${name}" already exists`, IndexPatternAlreadyExists);
super(`An index pattern of "${name}" already exists`);
}
}
@ -40,8 +39,7 @@ export class IndexPatternMissingIndices extends KbnError {
const defaultMessage = "IndexPattern's configured pattern does not match any indices";
super(
message && message.length ? `No matching indices found: ${message}` : defaultMessage,
IndexPatternMissingIndices
message && message.length ? `No matching indices found: ${message}` : defaultMessage
);
}
}
@ -51,7 +49,7 @@ export class IndexPatternMissingIndices extends KbnError {
*/
export class NoDefinedIndexPatterns extends KbnError {
constructor() {
super('Define at least one index pattern to continue', NoDefinedIndexPatterns);
super('Define at least one index pattern to continue');
}
}
@ -60,6 +58,6 @@ export class NoDefinedIndexPatterns extends KbnError {
*/
export class NoDefaultIndexPattern extends KbnError {
constructor() {
super('Please specify a default index pattern', NoDefaultIndexPattern);
super('Please specify a default index pattern');
}
}

View file

@ -21,8 +21,7 @@ import { defaults, pluck, last, get } from 'lodash';
import { IndexedArray } from 'ui/indexed_array';
import { IndexPattern } from './index_pattern';
// @ts-ignore
import { DuplicateField } from 'ui/errors';
import { DuplicateField } from '../../../../../../plugins/kibana_utils/public';
// @ts-ignore
import mockLogStashFields from '../../../../../../fixtures/logstash_fields';
// @ts-ignore

View file

@ -24,14 +24,13 @@ import { EuiButton, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import React from 'react';
import chrome from 'ui/chrome';
// @ts-ignore
import { SavedObjectNotFound, DuplicateField } from 'ui/errors';
// @ts-ignore
import { fieldFormats } from 'ui/registry/field_formats';
// @ts-ignore
import { expandShorthand } from 'ui/utils/mapping_setup';
import { toastNotifications } from 'ui/notify';
import { findObjectByTitle } from 'ui/saved_objects';
import { SavedObjectsClientContract } from 'src/core/public';
import { SavedObjectNotFound, DuplicateField } from '../../../../../../plugins/kibana_utils/public';
import { IndexPatternMissingIndices } from '../errors';
import { Field, FieldList, FieldType } from '../fields';

View file

@ -30,7 +30,7 @@ import dashboardTemplate from './dashboard_app.html';
import dashboardListingTemplate from './listing/dashboard_listing_ng_wrapper.html';
import { DashboardConstants, createDashboardEditUrl } from './dashboard_constants';
import { InvalidJSONProperty, SavedObjectNotFound } from 'ui/errors';
import { InvalidJSONProperty, SavedObjectNotFound } from '../../../../../plugins/kibana_utils/public';
import { FeatureCatalogueRegistryProvider, FeatureCatalogueCategory } from 'ui/registry/feature_catalogue';
import { SavedObjectsClientProvider } from 'ui/saved_objects';
import { recentlyAccessed } from 'ui/persisted_log';

View file

@ -35,19 +35,6 @@ jest.mock('../components/header', () => ({
Header: () => 'Header',
}));
jest.mock('ui/errors', () => ({
SavedObjectNotFound: class SavedObjectNotFound extends Error {
constructor(options) {
super();
for (const option in options) {
if (options.hasOwnProperty(option)) {
this[option] = options[option];
}
}
}
},
}));
jest.mock('ui/chrome', () => ({
addBasePath: () => '',
getInjected: () => ['index-pattern', 'visualization', 'dashboard', 'search'],

View file

@ -24,19 +24,6 @@ import { Flyout } from '../flyout';
jest.mock('ui/kfetch', () => ({ kfetch: jest.fn() }));
jest.mock('ui/errors', () => ({
SavedObjectNotFound: class SavedObjectNotFound extends Error {
constructor(options) {
super();
for (const option in options) {
if (options.hasOwnProperty(option)) {
this[option] = options[option];
}
}
}
},
}));
jest.mock('../../../../../lib/import_file', () => ({
importFile: jest.fn(),
}));

View file

@ -22,19 +22,6 @@ import { shallowWithIntl } from 'test_utils/enzyme_helpers';
jest.mock('ui/kfetch', () => ({ kfetch: jest.fn() }));
jest.mock('ui/errors', () => ({
SavedObjectNotFound: class SavedObjectNotFound extends Error {
constructor(options) {
super();
for (const option in options) {
if (options.hasOwnProperty(option)) {
this[option] = options[option];
}
}
}
},
}));
jest.mock('ui/chrome', () => ({
addBasePath: () => ''
}));

View file

@ -24,19 +24,6 @@ import { keyCodes } from '@elastic/eui/lib/services';
jest.mock('ui/kfetch', () => ({ kfetch: jest.fn() }));
jest.mock('ui/errors', () => ({
SavedObjectNotFound: class SavedObjectNotFound extends Error {
constructor(options) {
super();
for (const option in options) {
if (options.hasOwnProperty(option)) {
this[option] = options[option];
}
}
}
},
}));
jest.mock('ui/chrome', () => ({
addBasePath: () => ''
}));

View file

@ -24,7 +24,8 @@ import {
saveObject,
} from '../resolve_saved_objects';
jest.mock('ui/errors', () => ({
jest.mock('../../../../../../../../../plugins/kibana_utils/public', () => ({
SavedObjectNotFound: class SavedObjectNotFound extends Error {
constructor(options) {
super();
@ -36,6 +37,7 @@ jest.mock('ui/errors', () => ({
}
},
}));
import { SavedObjectNotFound } from '../../../../../../../../../plugins/kibana_utils/public';
describe('resolveSavedObjects', () => {
describe('resolveSavedObjects', () => {
@ -81,7 +83,6 @@ describe('resolveSavedObjects', () => {
return {
applyESResp: async () => {},
save: async () => {
const { SavedObjectNotFound } = require('ui/errors');
throw new SavedObjectNotFound({
savedObjectType: 'index-pattern',
});
@ -95,7 +96,6 @@ describe('resolveSavedObjects', () => {
return {
applyESResp: async () => {},
save: async () => {
const { SavedObjectNotFound } = require('ui/errors');
throw new SavedObjectNotFound({
savedObjectType: 'index-pattern',
});
@ -109,7 +109,6 @@ describe('resolveSavedObjects', () => {
return {
applyESResp: async () => {},
save: async () => {
const { SavedObjectNotFound } = require('ui/errors');
throw new SavedObjectNotFound({
savedObjectType: 'index-pattern',
});
@ -175,7 +174,6 @@ describe('resolveSavedObjects', () => {
return {
applyESResp: async () => {},
save: async () => {
const { SavedObjectNotFound } = require('ui/errors');
throw new SavedObjectNotFound({
savedObjectType: 'search',
});
@ -189,7 +187,6 @@ describe('resolveSavedObjects', () => {
return {
applyESResp: async () => {},
save: async () => {
const { SavedObjectNotFound } = require('ui/errors');
throw new SavedObjectNotFound({
savedObjectType: 'index-pattern',
});
@ -204,7 +201,6 @@ describe('resolveSavedObjects', () => {
savedSearchId: '1',
applyESResp: async () => {},
save: async () => {
const { SavedObjectNotFound } = require('ui/errors');
throw new SavedObjectNotFound({
savedObjectType: 'index-pattern',
});

View file

@ -17,7 +17,7 @@
* under the License.
*/
import { SavedObjectNotFound } from 'ui/errors';
import { SavedObjectNotFound } from '../../../../../../../../plugins/kibana_utils/public';
import { i18n } from '@kbn/i18n';
async function getSavedObject(doc, services) {

View file

@ -20,8 +20,7 @@
// @ts-ignore
import { i18n } from '@kbn/i18n';
import { AggConfig } from '../../vis';
// @ts-ignore
import { SavedObjectNotFound } from '../../errors';
import { SavedObjectNotFound } from '../../../../../plugins/kibana_utils/public';
import { FieldParamEditor } from '../../vis/editors/default/controls/field';
import { BaseParamType } from './base';
import { toastNotifications } from '../../notify';

View file

@ -20,7 +20,7 @@ import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiSpacer } from '@elastic/eui';
import { toastNotifications } from '../../notify';
import { RequestFailure } from '../../errors';
import { RequestFailure } from './errors';
import { RequestStatus } from './req_status';
import { SearchError } from '../search_strategy/search_error';
import { ShardFailureOpenModalButton } from './components/shard_failure_open_modal_button';

View file

@ -0,0 +1,34 @@
/*
* 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 { KbnError } from '../../../../../plugins/kibana_utils/public';
/**
* Request Failure - When an entire multi request fails
* @param {Error} err - the Error that came back
* @param {Object} resp - optional HTTP response
*/
export class RequestFailure extends KbnError {
public resp: any;
constructor(err: any, resp?: any) {
err = err || false;
super(`Request to Elasticsearch failed: ${JSON.stringify(resp || err.message)}`);
this.resp = resp;
}
}

View file

@ -1,249 +0,0 @@
/*
* 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 angular from 'angular';
import { createLegacyClass } from './utils/legacy_class';
const canStack = (function () {
const err = new Error();
return !!err.stack;
}());
// abstract error class
export class KbnError {
constructor(msg, constructor) {
this.message = msg;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, constructor || KbnError);
} else if (canStack) {
this.stack = (new Error()).stack;
} else {
this.stack = '';
}
}
/**
* If the error permits, propagate the error to be rendered on screen
*/
displayToScreen() {
throw this;
}
}
// Note, you can't extend the built in Error class:
// http://stackoverflow.com/questions/33870684/why-doesnt-instanceof-work-on-instances-of-error-subclasses-under-babel-node
// Hence we are inheriting from it this way, instead of using extends Error, and this will then preserve
// instanceof checks.
try {
createLegacyClass(KbnError).inherits(Error);
} catch (e) {
// Avoid TypeError: Cannot redefine property: prototype
}
/**
* Request Failure - When an entire multi request fails
* @param {Error} err - the Error that came back
* @param {Object} resp - optional HTTP response
*/
export class RequestFailure extends KbnError {
constructor(err, resp) {
err = err || false;
super(`Request to Elasticsearch failed: ${angular.toJson(resp || err.message)}`,
RequestFailure);
this.origError = err;
this.resp = resp;
}
}
/**
* FetchFailure Error - when there is an error getting a doc or search within
* a multi-response response body
* @param {Object} resp - The response from es.
*/
export class FetchFailure extends KbnError {
constructor(resp) {
super(
`Failed to get the doc: ${angular.toJson(resp)}`,
FetchFailure);
this.resp = resp;
}
}
/**
* A doc was re-indexed but it was out of date.
* @param {Object} resp - The response from es (one of the multi-response responses).
*/
export class VersionConflict extends KbnError {
constructor(resp) {
super(
'Failed to store document changes do to a version conflict.',
VersionConflict);
this.resp = resp;
}
}
/**
* there was a conflict storing a doc
* @param {String} field - the fields which contains the conflict
*/
export class MappingConflict extends KbnError {
constructor(field) {
super(
`Field "${field}" is defined with at least two different types in indices matching the pattern`,
MappingConflict);
}
}
/**
* a field mapping was using a restricted fields name
* @param {String} field - the fields which contains the conflict
*/
export class RestrictedMapping extends KbnError {
constructor(field, index) {
let msg = `"${field}" is a restricted field name`;
if (index) msg += `, found it while attempting to fetch mapping for index pattern: ${index}`;
super(msg, RestrictedMapping);
}
}
/**
* a non-critical cache write to elasticsearch failed
*/
export class CacheWriteFailure extends KbnError {
constructor() {
super(
'A Elasticsearch cache write has failed.',
CacheWriteFailure);
}
}
/**
* when a field mapping is requested for an unknown field
* @param {String} name - the field name
*/
export class FieldNotFoundInCache extends KbnError {
constructor(name) {
super(
`The "${name}" field was not found in the cached mappings`,
FieldNotFoundInCache);
}
}
/**
* when a mapping already exists for a field the user is attempting to add
* @param {String} name - the field name
*/
export class DuplicateField extends KbnError {
constructor(name) {
super(
`The field "${name}" already exists in this mapping`,
DuplicateField);
}
}
/**
* A saved object was not found
*/
export class SavedObjectNotFound extends KbnError {
constructor(type, id, link) {
const idMsg = id ? ` (id: ${id})` : '';
let message = `Could not locate that ${type}${idMsg}`;
if (link) {
message += `, [click here to re-create it](${link})`;
}
super(message, SavedObjectNotFound);
this.savedObjectType = type;
this.savedObjectId = id;
}
}
export class PersistedStateError extends KbnError {
constructor() {
super(
'Error with the persisted state',
PersistedStateError);
}
}
/**
* This error is for scenarios where a saved object is detected that has invalid JSON properties.
* There was a scenario where we were importing objects with double-encoded JSON, and the system
* was silently failing. This error is now thrown in those scenarios.
*/
export class InvalidJSONProperty extends KbnError {
constructor(message) {
super(message);
}
}
/**
* UI Errors
*/
export class VislibError extends KbnError {
constructor(message) {
super(message);
}
displayToScreen(handler) {
handler.error(this.message);
}
}
export class ContainerTooSmall extends VislibError {
constructor() {
super('This container is too small to render the visualization');
}
}
export class InvalidWiggleSelection extends VislibError {
constructor() {
super('In wiggle mode the area chart requires ordered values on the x-axis. Try using a Histogram or Date Histogram aggregation.');
}
}
export class PieContainsAllZeros extends VislibError {
constructor() {
super('No results displayed because all values equal 0.');
}
}
export class InvalidLogScaleValues extends VislibError {
constructor() {
super('Values less than 1 cannot be displayed on a log scale');
}
}
export class StackedBarChartConfig extends VislibError {
constructor(message) {
super(message);
}
}
export class NoResults extends VislibError {
constructor() {
super('No results found');
}
}

View file

@ -22,7 +22,7 @@ import sinon from 'sinon';
import noDigestPromises from 'test_utils/no_digest_promises';
import ngMock from 'ng_mock';
import expect from '@kbn/expect';
import { PersistedStateError } from '../../errors';
import { PersistedStateError } from '../errors';
import '..';
let PersistedState;

View file

@ -0,0 +1,26 @@
/*
* 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 { KbnError } from '../../../../plugins/kibana_utils/public';
export class PersistedStateError extends KbnError {
constructor() {
super('Error with the persisted state');
}
}

View file

@ -25,9 +25,10 @@
import _ from 'lodash';
import toPath from 'lodash/internal/toPath';
import { PersistedStateError } from '../errors';
import { PersistedStateError } from './errors';
import { SimpleEmitter } from '../utils/simple_emitter';
function prepSetParams(key, value, path) {
// key must be the value, set the entire state using it
if (_.isUndefined(value) && (_.isPlainObject(key) || path.length > 0)) {

View file

@ -25,7 +25,7 @@ import BluebirdPromise from 'bluebird';
import { SavedObjectProvider } from '../saved_object';
import StubIndexPatternProv from 'test_utils/stub_index_pattern';
import { SavedObjectsClientProvider } from '../saved_objects_client_provider';
import { InvalidJSONProperty } from '../../errors';
import { InvalidJSONProperty } from '../../../../../plugins/kibana_utils/public';
const getConfig = cfg => cfg;

View file

@ -31,7 +31,8 @@
import angular from 'angular';
import _ from 'lodash';
import { InvalidJSONProperty, SavedObjectNotFound } from '../errors';
import { InvalidJSONProperty, SavedObjectNotFound } from '../../../../plugins/kibana_utils/public';
import { expandShorthand } from '../utils/mapping_setup';
import { SearchSourceProvider } from '../courier/search_source';

View file

@ -22,7 +22,7 @@ import React from 'react';
import { i18n } from '@kbn/i18n';
import { MarkdownSimple } from '../../../core_plugins/kibana_react/public/markdown';
import { toastNotifications } from 'ui/notify';
import { SavedObjectNotFound } from '../errors';
import { SavedObjectNotFound } from '../../../../plugins/kibana_utils/public';
import { uiModules } from '../modules';
uiModules.get('kibana/url')

View file

@ -0,0 +1,56 @@
/*
* 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.
*/
/* eslint-disable max-classes-per-file */
import { KbnError } from '../../../../plugins/kibana_utils/public';
export class VislibError extends KbnError {
constructor(message: string) {
super(message);
}
displayToScreen(handler: any) {
handler.error(this.message);
}
}
export class InvalidLogScaleValues extends VislibError {
constructor() {
super('Values less than 1 cannot be displayed on a log scale');
}
}
export class ContainerTooSmall extends VislibError {
constructor() {
super('This container is too small to render the visualization');
}
}
export class PieContainsAllZeros extends VislibError {
constructor() {
super('No results displayed because all values equal 0.');
}
}
export class NoResults extends VislibError {
constructor() {
super('No results found');
}
}

View file

@ -18,7 +18,7 @@
*/
import _ from 'lodash';
import { ContainerTooSmall } from '../../errors';
import { ContainerTooSmall } from '../errors';
/**
* Common errors shared between constructors

View file

@ -25,7 +25,7 @@ import { AxisTitle } from './axis_title';
import { AxisLabels } from './axis_labels';
import { AxisScale } from './axis_scale';
import { AxisConfig } from './axis_config';
import { VislibError } from '../../../errors';
import { VislibError } from '../../errors';
export class Axis extends ErrorHandler {
constructor(visConfig, axisConfigArgs) {

View file

@ -21,9 +21,10 @@ import d3 from 'd3';
import _ from 'lodash';
import moment from 'moment';
import { InvalidLogScaleValues } from '../../../errors';
import { InvalidLogScaleValues } from '../../errors';
import { timeTicks } from './time_ticks';
export class AxisScale {
constructor(axisConfig, visConfig) {
this.axisConfig = axisConfig;

View file

@ -20,7 +20,7 @@
import d3 from 'd3';
import _ from 'lodash';
import MarkdownIt from 'markdown-it';
import { NoResults } from '../../errors';
import { NoResults } from '../errors';
import { Binder } from '../../binder';
import { Layout } from './layout/layout';
import { ChartTitle } from './chart_title';

View file

@ -21,7 +21,7 @@ import _ from 'lodash';
import d3 from 'd3';
import { EventEmitter } from 'events';
import chrome from '../chrome';
import { KbnError } from '../errors';
import { VislibError } from './errors';
import { VisConfig } from './lib/vis_config';
import { Handler } from './lib/handler';
import { setHierarchicalTooltipFormatter } from '../vis/components/tooltip/_hierarchical_tooltip_formatter';
@ -98,7 +98,7 @@ export function VislibVisProvider(Private) {
this.handler[method]();
} catch (error) {
if (error instanceof KbnError) {
if (error instanceof VislibError) {
error.displayToScreen(this.handler);
} else {
throw error;

View file

@ -21,7 +21,7 @@ import d3 from 'd3';
import _ from 'lodash';
import $ from 'jquery';
import numeral from 'numeral';
import { PieContainsAllZeros, ContainerTooSmall } from '../../errors';
import { PieContainsAllZeros, ContainerTooSmall } from '../errors';
import { Chart } from './_chart';
import { truncateLabel } from '../components/labels/truncate_labels';

View file

@ -18,47 +18,10 @@
*/
import expect from '@kbn/expect';
import {
RequestFailure,
FetchFailure,
VersionConflict,
MappingConflict,
RestrictedMapping,
CacheWriteFailure,
FieldNotFoundInCache,
DuplicateField,
SavedObjectNotFound,
PersistedStateError,
VislibError,
ContainerTooSmall,
InvalidWiggleSelection,
PieContainsAllZeros,
InvalidLogScaleValues,
StackedBarChartConfig,
NoResults,
KbnError
} from '../errors';
import { DuplicateField, SavedObjectNotFound, KbnError } from './errors';
describe('ui/errors', () => {
const errors = [
new RequestFailure('an error', { }),
new FetchFailure({ }),
new VersionConflict({ }),
new MappingConflict({ }),
new RestrictedMapping('field', 'indexPattern'),
new CacheWriteFailure(),
new FieldNotFoundInCache('aname'),
new DuplicateField('dupfield'),
new SavedObjectNotFound('dashboard', '123'),
new PersistedStateError(),
new VislibError('err'),
new ContainerTooSmall(),
new InvalidWiggleSelection(),
new PieContainsAllZeros(),
new InvalidLogScaleValues(),
new StackedBarChartConfig('err'),
new NoResults()
];
describe('errors', () => {
const errors = [new DuplicateField('dupfield'), new SavedObjectNotFound('dashboard', '123')];
errors.forEach(error => {
const className = error.constructor.name;
@ -70,7 +33,7 @@ describe('ui/errors', () => {
expect(error.stack).to.not.be.empty();
});
it (`${className} is an instance of KbnError`, () => {
it(`${className} is an instance of KbnError`, () => {
expect(error instanceof KbnError).to.be(true);
});
});

View file

@ -0,0 +1,70 @@
/*
* 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.
*/
/* eslint-disable max-classes-per-file */
// abstract error class
export class KbnError extends Error {
constructor(message: string) {
super(message);
Object.setPrototypeOf(this, new.target.prototype);
}
}
/**
* when a mapping already exists for a field the user is attempting to add
* @param {String} name - the field name
*/
export class DuplicateField extends KbnError {
constructor(name: string) {
super(`The field "${name}" already exists in this mapping`);
}
}
/**
* A saved object was not found
*/
export class SavedObjectNotFound extends KbnError {
public savedObjectType: string;
public savedObjectId?: string;
constructor(type: string, id?: string, link?: string) {
const idMsg = id ? ` (id: ${id})` : '';
let message = `Could not locate that ${type}${idMsg}`;
if (link) {
message += `, [click here to re-create it](${link})`;
}
super(message);
this.savedObjectType = type;
this.savedObjectId = id;
}
}
/**
* This error is for scenarios where a saved object is detected that has invalid JSON properties.
* There was a scenario where we were importing objects with double-encoded JSON, and the system
* was silently failing. This error is now thrown in those scenarios.
*/
export class InvalidJSONProperty extends KbnError {
constructor(message: string) {
super(message);
}
}

View file

@ -0,0 +1,20 @@
/*
* 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.
*/
export * from './errors';

View file

@ -19,3 +19,4 @@
export * from './store';
export * from './parse';
export * from './errors';

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { KbnError } from 'ui/errors';
import { KbnError } from '../../../../../../src/plugins/kibana_utils/public';
export class MLRequestFailure extends KbnError {
// takes an Error object and and optional response object