From 57a70bb334ce4e67ffdb6df9c6871b88378f85a4 Mon Sep 17 00:00:00 2001 From: Stacey Gammon Date: Tue, 4 Apr 2017 08:47:33 -0400 Subject: [PATCH] Convert default to named exports - errors (#10986) * Convert default to named exports - errors * Make all error classes use class syntax and extends add tests * Extending Error apparently doesn't work * Merge PR #11004 to try to fix test failures --- src/ui/public/__tests__/errors.js | 70 ++++ .../public/courier/_redirect_when_missing.js | 4 +- .../courier/data_source/_doc_send_to_es.js | 6 +- .../courier/saved_object/saved_object.js | 4 +- src/ui/public/errors.js | 322 +++++++++--------- .../__tests__/_index_pattern.js | 4 +- .../public/index_patterns/_index_pattern.js | 6 +- .../public/index_patterns/index_patterns.js | 4 +- .../__tests__/persisted_state_provider.js | 8 +- .../public/persisted_state/persisted_state.js | 8 +- src/ui/public/vislib/lib/_error_handler.js | 4 +- src/ui/public/vislib/lib/axis/axis.js | 4 +- src/ui/public/vislib/lib/axis/axis_scale.js | 4 +- src/ui/public/vislib/lib/handler.js | 4 +- src/ui/public/vislib/vis.js | 4 +- .../public/vislib/visualizations/pie_chart.js | 6 +- .../vislib/visualizations/point_series.js | 4 +- .../point_series/_point_series.js | 6 +- .../point_series/column_chart.js | 4 +- test/support/page_objects/dashboard_page.js | 5 +- 20 files changed, 267 insertions(+), 214 deletions(-) create mode 100644 src/ui/public/__tests__/errors.js diff --git a/src/ui/public/__tests__/errors.js b/src/ui/public/__tests__/errors.js new file mode 100644 index 00000000000000..3c98856f119f68 --- /dev/null +++ b/src/ui/public/__tests__/errors.js @@ -0,0 +1,70 @@ +import expect from 'expect.js'; +import { + SearchTimeout, + RequestFailure, + FetchFailure, + ShardFailure, + VersionConflict, + MappingConflict, + RestrictedMapping, + CacheWriteFailure, + FieldNotFoundInCache, + DuplicateField, + SavedObjectNotFound, + IndexPatternMissingIndices, + NoDefinedIndexPatterns, + NoDefaultIndexPattern, + PersistedStateError, + VislibError, + ContainerTooSmall, + InvalidWiggleSelection, + PieContainsAllZeros, + InvalidLogScaleValues, + StackedBarChartConfig, + NotEnoughData, + NoResults, + KbnError +} from 'ui/errors'; + +describe('ui/errors', () => { + const errors = [ + new SearchTimeout(), + new RequestFailure('an error', { }), + new FetchFailure({ }), + new ShardFailure({ '_shards' : 5 }), + new VersionConflict({ }), + new MappingConflict({ }), + new RestrictedMapping('field', 'indexPattern'), + new CacheWriteFailure(), + new FieldNotFoundInCache('aname'), + new DuplicateField('dupfield'), + new SavedObjectNotFound('dashboard', '123'), + new IndexPatternMissingIndices(), + new NoDefinedIndexPatterns(), + new NoDefaultIndexPattern(), + new PersistedStateError(), + new VislibError('err'), + new ContainerTooSmall(), + new InvalidWiggleSelection(), + new PieContainsAllZeros(), + new InvalidLogScaleValues(), + new StackedBarChartConfig('err'), + new NotEnoughData('nodata'), + new NoResults() + ]; + + errors.forEach(error => { + const className = error.constructor.name; + it(`${className} has a message`, () => { + expect(error.message).to.not.be.empty(); + }); + + it(`${className} has a stack trace`, () => { + expect(error.stack).to.not.be.empty(); + }); + + it (`${className} is an instance of KbnError`, () => { + expect(error instanceof KbnError).to.be(true); + }); + }); +}); diff --git a/src/ui/public/courier/_redirect_when_missing.js b/src/ui/public/courier/_redirect_when_missing.js index 64178f084eb3a3..41ed5fa85051ae 100644 --- a/src/ui/public/courier/_redirect_when_missing.js +++ b/src/ui/public/courier/_redirect_when_missing.js @@ -1,8 +1,6 @@ -import errors from 'ui/errors'; +import { SavedObjectNotFound } from 'ui/errors'; export default function RedirectWhenMissingFn($location, kbnUrl, Notifier, Promise) { - const SavedObjectNotFound = errors.SavedObjectNotFound; - const notify = new Notifier(); /** diff --git a/src/ui/public/courier/data_source/_doc_send_to_es.js b/src/ui/public/courier/data_source/_doc_send_to_es.js index 393df5aa550c44..6d3fa0bd6a2f58 100644 --- a/src/ui/public/courier/data_source/_doc_send_to_es.js +++ b/src/ui/public/courier/data_source/_doc_send_to_es.js @@ -7,7 +7,7 @@ import _ from 'lodash'; -import errors from 'ui/errors'; +import { VersionConflict, RequestFailure } from 'ui/errors'; import RequestQueueProvider from 'ui/courier/_request_queue'; import FetchProvider from 'ui/courier/fetch/fetch'; @@ -36,7 +36,7 @@ export default function (Promise, Private, es, esAdmin, kbnIndex) { const client = [].concat(params.index).includes(kbnIndex) ? esAdmin : es; return client[method](params) .then(function (resp) { - if (resp.status === 409) throw new errors.VersionConflict(resp); + if (resp.status === 409) throw new VersionConflict(resp); doc._storeVersion(resp._version); doc.id(resp._id); @@ -85,7 +85,7 @@ export default function (Promise, Private, es, esAdmin, kbnIndex) { }) .catch(function (err) { // cast the error - throw new errors.RequestFailure(err); + throw new RequestFailure(err); }); }; } diff --git a/src/ui/public/courier/saved_object/saved_object.js b/src/ui/public/courier/saved_object/saved_object.js index 1c4173c0568001..e46fbb7da5ff03 100644 --- a/src/ui/public/courier/saved_object/saved_object.js +++ b/src/ui/public/courier/saved_object/saved_object.js @@ -12,7 +12,7 @@ import angular from 'angular'; import _ from 'lodash'; -import errors from 'ui/errors'; +import { SavedObjectNotFound } from 'ui/errors'; import uuid from 'node-uuid'; import MappingSetupProvider from 'ui/utils/mapping_setup'; @@ -211,7 +211,7 @@ export default function SavedObjectFactory(esAdmin, kbnIndex, Promise, Private, this.applyESResp = (resp) => { this._source = _.cloneDeep(resp._source); - if (resp.found != null && !resp.found) throw new errors.SavedObjectNotFound(esType, this.id); + if (resp.found != null && !resp.found) throw new SavedObjectNotFound(esType, this.id); const meta = resp._source.kibanaSavedObjectMeta || {}; delete resp._source.kibanaSavedObjectMeta; diff --git a/src/ui/public/errors.js b/src/ui/public/errors.js index 6be8837aa4abf3..2aff7efd9eb50a 100644 --- a/src/ui/public/errors.js +++ b/src/ui/public/errors.js @@ -1,229 +1,226 @@ -import _ from 'lodash'; import angular from 'angular'; +import _ from 'lodash'; const canStack = (function () { const err = new Error(); return !!err.stack; }()); -const errors = {}; - // abstract error class -function KbnError(msg, constructor) { - this.message = msg; - - Error.call(this, this.message); - if (Error.captureStackTrace) { - Error.captureStackTrace(this, constructor || KbnError); - } else if (canStack) { - this.stack = (new Error()).stack; - } else { - this.stack = ''; +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; } } -errors.KbnError = KbnError; +// 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. _.class(KbnError).inherits(Error); -/** - * If the error permits, propagate the error to be rendered on screen - * @param handler the handlers that can render the error message to the screen. - */ -KbnError.prototype.displayToScreen = function () { - throw this; -}; - -/** - * HastyRefresh error class - * @param {String} [msg] - An error message that will probably end up in a log. - */ -errors.HastyRefresh = function HastyRefresh() { - KbnError.call(this, - 'Courier attempted to start a query before the previous had finished.', - errors.HastyRefresh); -}; -_.class(errors.HastyRefresh).inherits(KbnError); - /** * SearchTimeout error class */ -errors.SearchTimeout = function SearchTimeout() { - KbnError.call(this, - 'All or part of your request has timed out. The data shown may be incomplete.', - errors.SearchTimeout); -}; -_.class(errors.SearchTimeout).inherits(KbnError); +export class SearchTimeout extends KbnError { + constructor() { + super('All or part of your request has timed out. The data shown may be incomplete.', + SearchTimeout); + } +} /** * Request Failure - When an entire mutli request fails * @param {Error} err - the Error that came back * @param {Object} resp - optional HTTP response */ -errors.RequestFailure = function RequestFailure(err, resp) { - err = err || false; - - KbnError.call(this, - 'Request to Elasticsearch failed: ' + angular.toJson(resp || err.message), - errors.RequestFailure); - - this.origError = err; - this.resp = resp; -}; -_.class(errors.RequestFailure).inherits(KbnError); +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 {String} [msg] - An error message that will probably end up in a log. + * @param {Object} resp - The response from es. */ -errors.FetchFailure = function FetchFailure(resp) { - KbnError.call(this, - 'Failed to get the doc: ' + angular.toJson(resp), - errors.FetchFailure); +export class FetchFailure extends KbnError { + constructor(resp) { + super( + 'Failed to get the doc: ' + angular.toJson(resp), + FetchFailure); - this.resp = resp; -}; -_.class(errors.FetchFailure).inherits(KbnError); + this.resp = resp; + } +} /** * ShardFailure Error - when one or more shards fail - * @param {String} [msg] - An error message that will probably end up in a log. + * @param {Object} resp - The response from es. */ -errors.ShardFailure = function ShardFailure(resp) { - KbnError.call(this, resp._shards.failed + ' of ' + resp._shards.total + ' shards failed.', - errors.ShardFailure); - - this.resp = resp; -}; -_.class(errors.ShardFailure).inherits(KbnError); +export class ShardFailure extends KbnError { + constructor(resp) { + super( + resp._shards.failed + ' of ' + resp._shards.total + ' shards failed.', + ShardFailure); + 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). */ -errors.VersionConflict = function VersionConflict(resp) { - KbnError.call(this, - 'Failed to store document changes do to a version conflict.', - errors.VersionConflict); - - this.resp = resp; -}; -_.class(errors.VersionConflict).inherits(KbnError); +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 */ -errors.MappingConflict = function MappingConflict(field) { - KbnError.call(this, - 'Field "' + field + '" is defined with at least two different types in indices matching the pattern', - errors.MappingConflict); -}; -_.class(errors.MappingConflict).inherits(KbnError); +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 */ -errors.RestrictedMapping = function RestrictedMapping(field, index) { - let msg = field + ' is a restricted field name'; - if (index) msg += ', found it while attempting to fetch mapping for index pattern: ' + index; +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; - KbnError.call(this, msg, errors.RestrictedMapping); -}; -_.class(errors.RestrictedMapping).inherits(KbnError); + super(msg, RestrictedMapping); + } +} /** * a non-critical cache write to elasticseach failed */ -errors.CacheWriteFailure = function CacheWriteFailure() { - KbnError.call(this, - 'A Elasticsearch cache write has failed.', - errors.CacheWriteFailure); -}; -_.class(errors.CacheWriteFailure).inherits(KbnError); +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 */ -errors.FieldNotFoundInCache = function FieldNotFoundInCache(name) { - KbnError.call(this, - 'The ' + name + ' field was not found in the cached mappings', - errors.FieldNotFoundInCache); -}; -_.class(errors.FieldNotFoundInCache).inherits(KbnError); +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 */ -errors.DuplicateField = function DuplicateField(name) { - KbnError.call(this, - 'The "' + name + '" field already exists in this mapping', - errors.DuplicateField); -}; -_.class(errors.DuplicateField).inherits(KbnError); +export class DuplicateField extends KbnError { + constructor(name) { + super( + 'The "' + name + '" field already exists in this mapping', + DuplicateField); + } +} /** * A saved object was not found - * @param {String} field - the fields which contains the conflict */ -errors.SavedObjectNotFound = function SavedObjectNotFound(type, id) { - this.savedObjectType = type; - this.savedObjectId = id; - const idMsg = id ? ' (id: ' + id + ')' : ''; - KbnError.call(this, - 'Could not locate that ' + type + idMsg, - errors.SavedObjectNotFound); -}; -_.class(errors.SavedObjectNotFound).inherits(KbnError); +export class SavedObjectNotFound extends KbnError { + constructor(type, id) { + const idMsg = id ? ' (id: ' + id + ')' : ''; + super( + 'Could not locate that ' + type + idMsg, + SavedObjectNotFound); + + this.savedObjectType = type; + this.savedObjectId = id; + } +} /** * Tried to call a method that relies on SearchSource having an indexPattern assigned */ -errors.IndexPatternMissingIndices = function IndexPatternMissingIndices() { - KbnError.call(this, - 'IndexPattern\'s configured pattern does not match any indices', - errors.IndexPatternMissingIndices); -}; -_.class(errors.IndexPatternMissingIndices).inherits(KbnError); +export class IndexPatternMissingIndices extends KbnError { + constructor() { + super( + 'IndexPattern\'s configured pattern does not match any indices', + IndexPatternMissingIndices); + } +} /** * Tried to call a method that relies on SearchSource having an indexPattern assigned */ -errors.NoDefinedIndexPatterns = function NoDefinedIndexPatterns() { - KbnError.call(this, - 'Define at least one index pattern to continue', - errors.NoDefinedIndexPatterns); -}; -_.class(errors.NoDefinedIndexPatterns).inherits(KbnError); - +export class NoDefinedIndexPatterns extends KbnError { + constructor() { + super( + 'Define at least one index pattern to continue', + NoDefinedIndexPatterns); + } +} /** * Tried to load a route besides management/kibana/index but you don't have a default index pattern! */ -errors.NoDefaultIndexPattern = function NoDefaultIndexPattern() { - KbnError.call(this, - 'Please specify a default index pattern', - errors.NoDefaultIndexPattern); -}; -_.class(errors.NoDefaultIndexPattern).inherits(KbnError); - - -errors.PersistedStateError = function PersistedStateError() { - KbnError.call(this, - 'This container is too small to render the visualization', - errors.ContainerTooSmall); -}; -_.class(errors.PersistedStateError).inherits(KbnError); +export class NoDefaultIndexPattern extends KbnError { + constructor() { + super( + 'Please specify a default index pattern', + NoDefaultIndexPattern); + } +} +export class PersistedStateError extends KbnError { + constructor() { + super( + 'Error with the persisted state', + PersistedStateError); + } +} /** * UI Errors */ -errors.VislibError = class VislibError extends KbnError { +export class VislibError extends KbnError { constructor(message) { super(message); } @@ -231,62 +228,51 @@ errors.VislibError = class VislibError extends KbnError { displayToScreen(handler) { handler.error(this.message); } -}; - +} -errors.ContainerTooSmall = class ContainerTooSmall extends errors.VislibError { +export class ContainerTooSmall extends VislibError { constructor() { super('This container is too small to render the visualization'); } -}; +} -errors.InvalidWiggleSelection = class InvalidWiggleSelection extends errors.VislibError { +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.'); } -}; - +} -errors.PieContainsAllZeros = class PieContainsAllZeros extends errors.VislibError { +export class PieContainsAllZeros extends VislibError { constructor() { super('No results displayed because all values equal 0.'); } -}; - +} -errors.InvalidLogScaleValues = class InvalidLogScaleValues extends errors.VislibError { +export class InvalidLogScaleValues extends VislibError { constructor() { super('Values less than 1 cannot be displayed on a log scale'); } -}; - +} -errors.StackedBarChartConfig = class StackedBarChartConfig extends errors.VislibError { +export class StackedBarChartConfig extends VislibError { constructor(message) { super(message); } -}; +} /** * error thrown when user tries to render an chart with less * than the required number of data points * @param {String} message - the message to provide with the error */ -errors.NotEnoughData = class NotEnoughData extends errors.VislibError { +export class NotEnoughData extends VislibError { constructor(message) { super(message); } -}; +} -errors.NoResults = class NoResults extends errors.VislibError { +export class NoResults extends VislibError { constructor() { super('No results found'); } -}; - - - - - - -export default errors; +} diff --git a/src/ui/public/index_patterns/__tests__/_index_pattern.js b/src/ui/public/index_patterns/__tests__/_index_pattern.js index cc4a4694854106..97f159e1d3500b 100644 --- a/src/ui/public/index_patterns/__tests__/_index_pattern.js +++ b/src/ui/public/index_patterns/__tests__/_index_pattern.js @@ -3,7 +3,7 @@ import sinon from 'auto-release-sinon'; import ngMock from 'ng_mock'; import expect from 'expect.js'; import Promise from 'bluebird'; -import errors from 'ui/errors'; +import { DuplicateField } from 'ui/errors'; import IndexedArray from 'ui/indexed_array'; import FixturesLogstashFieldsProvider from 'fixtures/logstash_fields'; import FixturesStubbedDocSourceResponseProvider from 'fixtures/stubbed_doc_source_response'; @@ -255,7 +255,7 @@ describe('index pattern', function () { expect(function () { indexPattern.addScriptedField(scriptedField.name, '\'new script\'', 'string'); }).to.throwError(function (e) { - expect(e).to.be.a(errors.DuplicateField); + expect(e).to.be.a(DuplicateField); }); }); }); diff --git a/src/ui/public/index_patterns/_index_pattern.js b/src/ui/public/index_patterns/_index_pattern.js index d82dfbec1353a7..1a769bd1e0541a 100644 --- a/src/ui/public/index_patterns/_index_pattern.js +++ b/src/ui/public/index_patterns/_index_pattern.js @@ -1,5 +1,5 @@ import _ from 'lodash'; -import errors from 'ui/errors'; +import { SavedObjectNotFound, DuplicateField } from 'ui/errors'; import angular from 'angular'; import getComputedFields from 'ui/index_patterns/_get_computed_fields'; import formatHit from 'ui/index_patterns/_format_hit'; @@ -69,7 +69,7 @@ export default function IndexPatternFactory(Private, Notifier, config, kbnIndex, function updateFromElasticSearch(indexPattern, response) { if (!response.found) { - throw new errors.SavedObjectNotFound(type, indexPattern.id); + throw new SavedObjectNotFound(type, indexPattern.id); } _.forOwn(mapping, (fieldMapping, name) => { @@ -212,7 +212,7 @@ export default function IndexPatternFactory(Private, Notifier, config, kbnIndex, const names = _.pluck(scriptedFields, 'name'); if (_.contains(names, name)) { - throw new errors.DuplicateField(name); + throw new DuplicateField(name); } this.fields.push({ diff --git a/src/ui/public/index_patterns/index_patterns.js b/src/ui/public/index_patterns/index_patterns.js index 5ac94c6093fb6d..4ce7047674eff0 100644 --- a/src/ui/public/index_patterns/index_patterns.js +++ b/src/ui/public/index_patterns/index_patterns.js @@ -1,5 +1,5 @@ import 'ui/filters/short_dots'; -import errors from 'ui/errors'; +import { IndexPatternMissingIndices } from 'ui/errors'; import IndexPatternsIndexPatternProvider from 'ui/index_patterns/_index_pattern'; import IndexPatternsPatternCacheProvider from 'ui/index_patterns/_pattern_cache'; import IndexPatternsGetIdsProvider from 'ui/index_patterns/_get_ids'; @@ -39,7 +39,7 @@ function IndexPatternsProvider(esAdmin, Notifier, Private, Promise, kbnIndex) { }; self.errors = { - MissingIndices: errors.IndexPatternMissingIndices + MissingIndices: IndexPatternMissingIndices }; self.cache = patternCache; diff --git a/src/ui/public/persisted_state/__tests__/persisted_state_provider.js b/src/ui/public/persisted_state/__tests__/persisted_state_provider.js index 296565bbe68343..404a443695caa5 100644 --- a/src/ui/public/persisted_state/__tests__/persisted_state_provider.js +++ b/src/ui/public/persisted_state/__tests__/persisted_state_provider.js @@ -3,7 +3,7 @@ import sinon from 'auto-release-sinon'; import noDigestPromises from 'test_utils/no_digest_promises'; import ngMock from 'ng_mock'; import expect from 'expect.js'; -import errors from 'ui/errors'; +import { PersistedStateError } from 'ui/errors'; import 'ui/persisted_state'; let PersistedState; @@ -62,7 +62,7 @@ describe('Persisted State Provider', function () { }; expect(run).to.throwException(function (err) { - expect(err).to.be.a(errors.PersistedStateError); + expect(err).to.be.a(PersistedStateError); }); }); @@ -86,7 +86,7 @@ describe('Persisted State Provider', function () { }; expect(run).to.throwException(function (err) { - expect(err).to.be.a(errors.PersistedStateError); + expect(err).to.be.a(PersistedStateError); }); }); @@ -100,7 +100,7 @@ describe('Persisted State Provider', function () { }; expect(run).to.throwException(function (err) { - expect(err).to.be.a(errors.PersistedStateError); + expect(err).to.be.a(PersistedStateError); }); }); }); diff --git a/src/ui/public/persisted_state/persisted_state.js b/src/ui/public/persisted_state/persisted_state.js index fa27fd8647fe59..3c8835c27ce756 100644 --- a/src/ui/public/persisted_state/persisted_state.js +++ b/src/ui/public/persisted_state/persisted_state.js @@ -6,7 +6,7 @@ import _ from 'lodash'; import toPath from 'lodash/internal/toPath'; -import errors from 'ui/errors'; +import { PersistedStateError } from 'ui/errors'; import SimpleEmitter from 'ui/utils/simple_emitter'; function prepSetParams(key, value, path) { @@ -54,13 +54,13 @@ export class PersistedState { // Some validations if (this._parent) { if (this._path.length <= 0) { - throw new errors.PersistedStateError('PersistedState child objects must contain a path'); + throw new PersistedStateError('PersistedState child objects must contain a path'); } if (!(this._parent instanceof PersistedState)) { - throw new errors.PersistedStateError('Parent object must be an instance of PersistedState'); + throw new PersistedStateError('Parent object must be an instance of PersistedState'); } } else if (!this._path.length && value && !_.isPlainObject(value)) { - throw new errors.PersistedStateError('State value must be a plain object'); + throw new PersistedStateError('State value must be a plain object'); } value = value || this._getDefault(); diff --git a/src/ui/public/vislib/lib/_error_handler.js b/src/ui/public/vislib/lib/_error_handler.js index 244be894587fc2..c364a6b22af4e5 100644 --- a/src/ui/public/vislib/lib/_error_handler.js +++ b/src/ui/public/vislib/lib/_error_handler.js @@ -1,5 +1,5 @@ import _ from 'lodash'; -import errors from 'ui/errors'; +import { ContainerTooSmall } from 'ui/errors'; export default function ErrorHandlerFactory() { @@ -28,7 +28,7 @@ export default function ErrorHandlerFactory() { const badHeight = _.isNaN(height) || height <= 0; if (badWidth || badHeight) { - throw new errors.ContainerTooSmall(); + throw new ContainerTooSmall(); } } } diff --git a/src/ui/public/vislib/lib/axis/axis.js b/src/ui/public/vislib/lib/axis/axis.js index eb20da44a4606a..171e84e298d633 100644 --- a/src/ui/public/vislib/lib/axis/axis.js +++ b/src/ui/public/vislib/lib/axis/axis.js @@ -6,7 +6,7 @@ import AxisTitleProvider from './axis_title'; import AxisLabelsProvider from './axis_labels'; import AxisScaleProvider from './axis_scale'; import AxisConfigProvider from './axis_config'; -import errors from 'ui/errors'; +import { VislibError } from 'ui/errors'; export default function AxisFactory(Private) { const ErrorHandler = Private(ErrorHandlerProvider); @@ -162,7 +162,7 @@ export default function AxisFactory(Private) { validate() { if (this.axisConfig.isLogScale() && this.axisConfig.isPercentage()) { - throw new errors.VislibError(`Can't mix percentage mode with log scale.`); + throw new VislibError(`Can't mix percentage mode with log scale.`); } } diff --git a/src/ui/public/vislib/lib/axis/axis_scale.js b/src/ui/public/vislib/lib/axis/axis_scale.js index 6b8f8177ee0e93..b0eabba47330e5 100644 --- a/src/ui/public/vislib/lib/axis/axis_scale.js +++ b/src/ui/public/vislib/lib/axis/axis_scale.js @@ -1,7 +1,7 @@ import d3 from 'd3'; import _ from 'lodash'; import moment from 'moment'; -import errors from 'ui/errors'; +import { InvalidLogScaleValues } from 'ui/errors'; export default function AxisScaleFactory() { class AxisScale { @@ -148,7 +148,7 @@ export default function AxisScaleFactory() { } throwLogScaleValuesError() { - throw new errors.InvalidLogScaleValues(); + throw new InvalidLogScaleValues(); } logDomain(min, max) { diff --git a/src/ui/public/vislib/lib/handler.js b/src/ui/public/vislib/lib/handler.js index 6045c9b6f51ebc..eadcae31ceb301 100644 --- a/src/ui/public/vislib/lib/handler.js +++ b/src/ui/public/vislib/lib/handler.js @@ -1,7 +1,7 @@ import d3 from 'd3'; import _ from 'lodash'; import $ from 'jquery'; -import errors from 'ui/errors'; +import { NoResults } from 'ui/errors'; import Binder from 'ui/binder'; import VislibLibLayoutLayoutProvider from './layout/layout'; import VislibLibChartTitleProvider from './chart_title'; @@ -104,7 +104,7 @@ export default function HandlerBaseClass(Private) { const dataType = this.data.type; if (!dataType) { - throw new errors.NoResults(); + throw new NoResults(); } } diff --git a/src/ui/public/vislib/vis.js b/src/ui/public/vislib/vis.js index 951a0e4dcea714..f2bd2d227bfd4e 100644 --- a/src/ui/public/vislib/vis.js +++ b/src/ui/public/vislib/vis.js @@ -1,7 +1,7 @@ import _ from 'lodash'; import d3 from 'd3'; import Binder from 'ui/binder'; -import errors from 'ui/errors'; +import { KbnError } from 'ui/errors'; import EventsProvider from 'ui/events'; import './styles/main.less'; import VislibLibResizeCheckerProvider from './lib/resize_checker'; @@ -110,7 +110,7 @@ export default function VisFactory(Private) { this.handler[method](); } catch (error) { - if (error instanceof errors.KbnError) { + if (error instanceof KbnError) { error.displayToScreen(this.handler); } else { throw error; diff --git a/src/ui/public/vislib/visualizations/pie_chart.js b/src/ui/public/vislib/visualizations/pie_chart.js index 692da1e4437c82..5a135e88eeba34 100644 --- a/src/ui/public/vislib/visualizations/pie_chart.js +++ b/src/ui/public/vislib/visualizations/pie_chart.js @@ -1,7 +1,7 @@ import d3 from 'd3'; import _ from 'lodash'; import $ from 'jquery'; -import errors from 'ui/errors'; +import { PieContainsAllZeros, ContainerTooSmall } from 'ui/errors'; import VislibVisualizationsChartProvider from './_chart'; export default function PieChartFactory(Private) { @@ -46,7 +46,7 @@ export default function PieChartFactory(Private) { }); if (isAllZeros) { - throw new errors.PieContainsAllZeros(); + throw new PieContainsAllZeros(); } } @@ -176,7 +176,7 @@ export default function PieChartFactory(Private) { const minHeight = 20; if (width <= minWidth || height <= minHeight) { - throw new errors.ContainerTooSmall(); + throw new ContainerTooSmall(); } } diff --git a/src/ui/public/vislib/visualizations/point_series.js b/src/ui/public/vislib/visualizations/point_series.js index 167e1f671c6d74..f0b8f6bca78bf3 100644 --- a/src/ui/public/vislib/visualizations/point_series.js +++ b/src/ui/public/vislib/visualizations/point_series.js @@ -1,7 +1,7 @@ import d3 from 'd3'; import _ from 'lodash'; import $ from 'jquery'; -import errors from 'ui/errors'; +import { ContainerTooSmall } from 'ui/errors'; import TooltipProvider from 'ui/vis/components/tooltip'; import VislibVisualizationsChartProvider from './_chart'; import VislibVisualizationsTimeMarkerProvider from './time_marker'; @@ -214,7 +214,7 @@ export default function PointSeriesFactory(Private) { const el = this; if (width < minWidth || height < minHeight) { - throw new errors.ContainerTooSmall(); + throw new ContainerTooSmall(); } if (addTimeMarker) { diff --git a/src/ui/public/vislib/visualizations/point_series/_point_series.js b/src/ui/public/vislib/visualizations/point_series/_point_series.js index c43e8dc6f1ceb6..1ca2903b8ba952 100644 --- a/src/ui/public/vislib/visualizations/point_series/_point_series.js +++ b/src/ui/public/vislib/visualizations/point_series/_point_series.js @@ -1,5 +1,5 @@ import _ from 'lodash'; -import errors from 'ui/errors'; +import { InvalidLogScaleValues, NotEnoughData } from 'ui/errors'; export default function PointSeriesProvider() { @@ -17,7 +17,7 @@ export default function PointSeriesProvider() { validateDataCompliesWithScalingMethod(data) { const invalidLogScale = data.values && data.values.some(d => d.y < 1); if (this.getValueAxis().axisConfig.isLogScale() && invalidLogScale) { - throw new errors.InvalidLogScaleValues(); + throw new InvalidLogScaleValues(); } } @@ -96,7 +96,7 @@ export default function PointSeriesProvider() { const notEnoughData = this.chartData.values.length < 2; if (notEnoughData) { - throw new errors.NotEnoughData(message); + throw new NotEnoughData(message); } } } diff --git a/src/ui/public/vislib/visualizations/point_series/column_chart.js b/src/ui/public/vislib/visualizations/point_series/column_chart.js index 6fc0fa2eaf6ec4..96f221b10311ad 100644 --- a/src/ui/public/vislib/visualizations/point_series/column_chart.js +++ b/src/ui/public/vislib/visualizations/point_series/column_chart.js @@ -1,5 +1,5 @@ import _ from 'lodash'; -import errors from 'ui/errors'; +import { ContainerTooSmall } from 'ui/errors'; import VislibVisualizationsPointSeriesProvider from './_point_series'; export default function ColumnChartFactory(Private) { @@ -187,7 +187,7 @@ export default function ColumnChartFactory(Private) { function widthFunc() { if (barWidth < minWidth) { - throw new errors.ContainerTooSmall(); + throw new ContainerTooSmall(); } if (isTimeScale) { diff --git a/test/support/page_objects/dashboard_page.js b/test/support/page_objects/dashboard_page.js index ce1288a6244d76..c859a1e7d1e5a3 100644 --- a/test/support/page_objects/dashboard_page.js +++ b/test/support/page_objects/dashboard_page.js @@ -221,9 +221,8 @@ export default class DashboardPage { } clickDashboardByLinkText(dashName) { - return this.findTimeout - .findByLinkText(dashName) - .click(); + PageObjects.common.debug('clickDashboardByLinkText: ' + dashName); + return PageObjects.common.try(() => this.findTimeout.findByLinkText(dashName).click()); } async searchForDashboardWithName(dashName) {