mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[elasticsearch] remove SetupError class (#8848)
This commit is contained in:
parent
c5ca1604ff
commit
908da97953
6 changed files with 13 additions and 96 deletions
|
@ -3,7 +3,6 @@ import Promise from 'bluebird';
|
|||
import sinon from 'sinon';
|
||||
import expect from 'expect.js';
|
||||
import url from 'url';
|
||||
import SetupError from '../setup_error';
|
||||
|
||||
import serverConfig from '../../../../../test/server_config';
|
||||
import checkEsVersion from '../check_es_version';
|
||||
|
@ -18,10 +17,6 @@ describe('plugins/elasticsearch', () => {
|
|||
beforeEach(function () {
|
||||
server = {
|
||||
log: sinon.stub(),
|
||||
// This is required or else we get a SetupError.
|
||||
config: () => ({
|
||||
get: sinon.stub(),
|
||||
}),
|
||||
plugins: {
|
||||
elasticsearch: {
|
||||
client: {
|
||||
|
@ -79,7 +74,7 @@ describe('plugins/elasticsearch', () => {
|
|||
try {
|
||||
await checkEsVersion(server, KIBANA_VERSION);
|
||||
} catch (e) {
|
||||
expect(e).to.be.a(SetupError);
|
||||
expect(e).to.be.a(Error);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -92,7 +87,7 @@ describe('plugins/elasticsearch', () => {
|
|||
try {
|
||||
await checkEsVersion(server, KIBANA_VERSION);
|
||||
} catch (e) {
|
||||
expect(e).to.be.a(SetupError);
|
||||
expect(e).to.be.a(Error);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import expect from 'expect.js';
|
|||
import Promise from 'bluebird';
|
||||
|
||||
import createKibanaIndex from '../create_kibana_index';
|
||||
import SetupError from '../setup_error';
|
||||
|
||||
describe('plugins/elasticsearch', function () {
|
||||
describe('lib/create_kibana_index', function () {
|
||||
|
@ -88,12 +87,12 @@ describe('plugins/elasticsearch', function () {
|
|||
});
|
||||
|
||||
describe('failure requests', function () {
|
||||
it('should reject with a SetupError', function () {
|
||||
it('should reject with an Error', function () {
|
||||
const error = new Error('Oops!');
|
||||
client.indices.create.returns(Promise.reject(error));
|
||||
const fn = createKibanaIndex(server);
|
||||
return fn.catch(function (err) {
|
||||
expect(err).to.be.a(SetupError);
|
||||
expect(err).to.be.a(Error);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -103,7 +102,6 @@ describe('plugins/elasticsearch', function () {
|
|||
const fn = createKibanaIndex(server);
|
||||
return fn.catch(function (err) {
|
||||
expect(err.message).to.be('Unable to create Kibana index ".my-kibana"');
|
||||
expect(err).to.have.property('origError', error);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -115,7 +113,6 @@ describe('plugins/elasticsearch', function () {
|
|||
const fn = createKibanaIndex(server);
|
||||
return fn.catch(function (err) {
|
||||
expect(err.message).to.be('Waiting for Kibana index ".my-kibana" to come online failed.');
|
||||
expect(err).to.have.property('origError', error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
import SetupError from '../setup_error';
|
||||
import expect from 'expect.js';
|
||||
|
||||
describe('plugins/elasticsearch', function () {
|
||||
describe('lib/setup_error', function () {
|
||||
|
||||
const server = {
|
||||
config: function () {
|
||||
return {
|
||||
get: function () {
|
||||
return { kibana: { index: '.my-kibana' } };
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const err = new SetupError(server, 'Oops! <%= kibana.index %>');
|
||||
|
||||
it('should allow config values in the message template', function () {
|
||||
expect(err).to.have.property('message', 'Oops! .my-kibana');
|
||||
});
|
||||
|
||||
it('should set the name of the error', function () {
|
||||
expect(err).to.have.property('name', 'SetupError');
|
||||
});
|
||||
|
||||
it('should set the stack trace', function () {
|
||||
expect(err).to.have.property('stack');
|
||||
expect(err.stack).to.match(/^SetupError/);
|
||||
});
|
||||
|
||||
it('should return the passed error if it is a SetupError', function () {
|
||||
const error = new SetupError(server, 'Oh Boy!', err);
|
||||
expect(error).to.have.property('message', 'Oops! .my-kibana');
|
||||
});
|
||||
|
||||
it('should store the original error', function () {
|
||||
const origError = new Error('Boom!');
|
||||
const error = new SetupError(server, 'Oh Boy!', origError);
|
||||
expect(error).to.have.property('origError', origError);
|
||||
});
|
||||
|
||||
it('should copy the stack from the origError', function () {
|
||||
const origError = new Error('Boom!');
|
||||
const error = new SetupError(server, 'Oh Boy!', origError);
|
||||
expect(error).to.have.property('stack', origError.stack);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
@ -7,7 +7,6 @@ import _ from 'lodash';
|
|||
import esBool from './es_bool';
|
||||
import semver from 'semver';
|
||||
import isEsCompatibleWithKibana from './is_es_compatible_with_kibana';
|
||||
import SetupError from './setup_error';
|
||||
|
||||
/**
|
||||
* tracks the node descriptions that get logged in warnings so
|
||||
|
@ -78,13 +77,11 @@ module.exports = function checkEsVersion(server, kibanaVersion) {
|
|||
|
||||
if (incompatibleNodes.length) {
|
||||
const incompatibleNodeNames = getHumanizedNodeNames(incompatibleNodes);
|
||||
|
||||
const errorMessage =
|
||||
throw new Error(
|
||||
`This version of Kibana requires Elasticsearch v` +
|
||||
`${kibanaVersion} on all nodes. I found ` +
|
||||
`the following incompatible nodes in your cluster: ${incompatibleNodeNames.join(',')}`;
|
||||
|
||||
throw new SetupError(server, errorMessage);
|
||||
`the following incompatible nodes in your cluster: ${incompatibleNodeNames.join(',')}`
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import SetupError from './setup_error';
|
||||
import { format } from 'util';
|
||||
import { mappings } from './kibana_index_mappings';
|
||||
|
||||
|
@ -6,12 +5,6 @@ module.exports = function (server) {
|
|||
const client = server.plugins.elasticsearch.client;
|
||||
const index = server.config().get('kibana.index');
|
||||
|
||||
function handleError(message) {
|
||||
return function (err) {
|
||||
throw new SetupError(server, message, err);
|
||||
};
|
||||
}
|
||||
|
||||
return client.indices.create({
|
||||
index: index,
|
||||
body: {
|
||||
|
@ -21,12 +14,16 @@ module.exports = function (server) {
|
|||
mappings
|
||||
}
|
||||
})
|
||||
.catch(handleError('Unable to create Kibana index "<%= kibana.index %>"'))
|
||||
.catch(() => {
|
||||
throw new Error(`Unable to create Kibana index "${index}"`);
|
||||
})
|
||||
.then(function () {
|
||||
return client.cluster.health({
|
||||
waitForStatus: 'yellow',
|
||||
index: index
|
||||
})
|
||||
.catch(handleError('Waiting for Kibana index "<%= kibana.index %>" to come online failed.'));
|
||||
.catch(() => {
|
||||
throw new Error(`Waiting for Kibana index "${index}" to come online failed.`);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
import _ from 'lodash';
|
||||
import util from 'util';
|
||||
|
||||
function SetupError(server, template, err) {
|
||||
const config = server.config().get();
|
||||
// don't override other setup errors
|
||||
if (err && err instanceof SetupError) return err;
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
this.name = this.constructor.name;
|
||||
this.message = _.template(template)(config);
|
||||
if (err) {
|
||||
this.origError = err;
|
||||
if (err.stack) this.stack = err.stack;
|
||||
}
|
||||
}
|
||||
util.inherits(SetupError, Error);
|
||||
module.exports = SetupError;
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue