mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -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] : []
|
isInvalidPackError(result.error) ? [result.error] : []
|
||||||
)),
|
)),
|
||||||
|
|
||||||
|
otherError$: find$
|
||||||
|
.mergeMap(result => (
|
||||||
|
isUnhandledError(result.error) ? [result.error] : []
|
||||||
|
)),
|
||||||
|
|
||||||
// { spec, message } objects produced when transforming deprecated
|
// { spec, message } objects produced when transforming deprecated
|
||||||
// settings for a plugin spec
|
// settings for a plugin spec
|
||||||
deprecation$: extendConfig$
|
deprecation$: extendConfig$
|
||||||
|
@ -132,3 +137,11 @@ export function findPluginSpecs(settings, config = defaultConfig(settings)) {
|
||||||
.mergeMap(result => result.invalidVersionSpecs),
|
.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);
|
assertInvalidPackError(error);
|
||||||
expect(error.message).to.contain('must export a function');
|
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 {
|
import {
|
||||||
PLUGINS_DIR,
|
PLUGINS_DIR,
|
||||||
assertInvalidDirectoryError,
|
assertInvalidDirectoryError,
|
||||||
assertInvalidPackError,
|
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
describe('plugin discovery/packs in directory', () => {
|
describe('plugin discovery/packs in directory', () => {
|
||||||
|
@ -55,15 +54,13 @@ describe('plugin discovery/packs in directory', () => {
|
||||||
.map(result => result.pack)
|
.map(result => result.pack)
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
|
|
||||||
errors.forEach(assertInvalidPackError);
|
|
||||||
packs.forEach(pack => expect(pack).to.be.a(PluginPack));
|
packs.forEach(pack => expect(pack).to.be.a(PluginPack));
|
||||||
// there should be one result for each item in PLUGINS_DIR
|
// there should be one result for each item in PLUGINS_DIR
|
||||||
expect(results).to.have.length(8);
|
expect(results).to.have.length(9);
|
||||||
// six of the fixtures are errors of some sorta
|
// six of the fixtures are errors of some sort
|
||||||
expect(errors).to.have.length(6);
|
expect(errors).to.have.length(7);
|
||||||
// two of them are valid
|
// two of them are valid
|
||||||
expect(packs).to.have.length(2);
|
expect(packs).to.have.length(2);
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,6 +8,7 @@ export async function scanMixin(kbnServer, server, config) {
|
||||||
pack$,
|
pack$,
|
||||||
invalidDirectoryError$,
|
invalidDirectoryError$,
|
||||||
invalidPackError$,
|
invalidPackError$,
|
||||||
|
otherError$,
|
||||||
deprecation$,
|
deprecation$,
|
||||||
invalidVersionSpec$,
|
invalidVersionSpec$,
|
||||||
spec$,
|
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$
|
invalidVersionSpec$
|
||||||
.map(spec => {
|
.map(spec => {
|
||||||
const name = spec.getId();
|
const name = spec.getId();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue