mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Show error when require(pack) fails (#16837)
This commit is contained in:
parent
8de986040f
commit
c8659b9a78
6 changed files with 36 additions and 6 deletions
|
@ -108,6 +108,11 @@ export function findPluginSpecs(settings, config = defaultConfig(settings)) {
|
|||
isInvalidPackError(result.error) ? [result.error] : []
|
||||
)),
|
||||
|
||||
otherError$: find$
|
||||
.mergeMap(result => (
|
||||
isUnhandledError(result.error) ? [result.error] : []
|
||||
)),
|
||||
|
||||
// { spec, message } objects produced when transforming deprecated
|
||||
// settings for a plugin spec
|
||||
deprecation$: extendConfig$
|
||||
|
@ -132,3 +137,11 @@ export function findPluginSpecs(settings, config = defaultConfig(settings)) {
|
|||
.mergeMap(result => result.invalidVersionSpecs),
|
||||
};
|
||||
}
|
||||
|
||||
function isUnhandledError(error) {
|
||||
return (
|
||||
error != null &&
|
||||
!isInvalidDirectoryError(error) &&
|
||||
!isInvalidPackError(error)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
const brokenRequire = require('does-not-exist'); // eslint-disable-line
|
||||
|
||||
module.exports = function (kibana) {
|
||||
return new kibana.Plugin({
|
||||
id: 'foo',
|
||||
});
|
||||
};
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"name": "foo",
|
||||
"version": "kibana"
|
||||
}
|
|
@ -71,6 +71,9 @@ describe('plugin discovery/plugin_pack', () => {
|
|||
assertInvalidPackError(error);
|
||||
expect(error.message).to.contain('must export a function');
|
||||
}));
|
||||
it('directory with code that fails when required', () => checkError(resolve(PLUGINS_DIR, 'broken_code'), error => {
|
||||
expect(error.message).to.contain('Cannot find module \'does-not-exist\'');
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -8,7 +8,6 @@ import { PluginPack } from '../plugin_pack';
|
|||
import {
|
||||
PLUGINS_DIR,
|
||||
assertInvalidDirectoryError,
|
||||
assertInvalidPackError,
|
||||
} from './utils';
|
||||
|
||||
describe('plugin discovery/packs in directory', () => {
|
||||
|
@ -55,15 +54,13 @@ describe('plugin discovery/packs in directory', () => {
|
|||
.map(result => result.pack)
|
||||
.filter(Boolean);
|
||||
|
||||
errors.forEach(assertInvalidPackError);
|
||||
packs.forEach(pack => expect(pack).to.be.a(PluginPack));
|
||||
// there should be one result for each item in PLUGINS_DIR
|
||||
expect(results).to.have.length(8);
|
||||
// six of the fixtures are errors of some sorta
|
||||
expect(errors).to.have.length(6);
|
||||
expect(results).to.have.length(9);
|
||||
// six of the fixtures are errors of some sort
|
||||
expect(errors).to.have.length(7);
|
||||
// two of them are valid
|
||||
expect(packs).to.have.length(2);
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -8,6 +8,7 @@ export async function scanMixin(kbnServer, server, config) {
|
|||
pack$,
|
||||
invalidDirectoryError$,
|
||||
invalidPackError$,
|
||||
otherError$,
|
||||
deprecation$,
|
||||
invalidVersionSpec$,
|
||||
spec$,
|
||||
|
@ -37,6 +38,11 @@ export async function scanMixin(kbnServer, server, config) {
|
|||
});
|
||||
}),
|
||||
|
||||
otherError$.do(error => {
|
||||
// rethrow unhandled errors, which will fail the server
|
||||
throw error;
|
||||
}),
|
||||
|
||||
invalidVersionSpec$
|
||||
.map(spec => {
|
||||
const name = spec.getId();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue