frontend-app-api: tweak error messaging to include more information about where undeclared inputs are from
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -289,7 +289,50 @@ describe('createExtensionInstance', () => {
|
||||
}),
|
||||
}),
|
||||
).toThrow(
|
||||
"Failed to instantiate extension 'core.test', received undeclared input(s) 'undeclared'",
|
||||
"Failed to instantiate extension 'core.test', received undeclared input 'undeclared' from extension 'core.test'",
|
||||
);
|
||||
});
|
||||
|
||||
it('should refuse to create an instance with multiple undeclared inputs', () => {
|
||||
expect(() =>
|
||||
createExtensionInstance({
|
||||
attachments: new Map([
|
||||
[
|
||||
'undeclared1',
|
||||
[
|
||||
createExtensionInstance({
|
||||
attachments: new Map(),
|
||||
config: { output: 'many1' },
|
||||
extension: simpleExtension,
|
||||
}),
|
||||
],
|
||||
],
|
||||
[
|
||||
'undeclared2',
|
||||
[
|
||||
createExtensionInstance({
|
||||
attachments: new Map(),
|
||||
config: { output: 'many1' },
|
||||
extension: simpleExtension,
|
||||
}),
|
||||
createExtensionInstance({
|
||||
attachments: new Map(),
|
||||
config: { output: 'many1' },
|
||||
extension: simpleExtension,
|
||||
}),
|
||||
],
|
||||
],
|
||||
]),
|
||||
config: undefined,
|
||||
extension: createExtension({
|
||||
id: 'core.test',
|
||||
attachTo: { id: 'ignored', input: 'ignored' },
|
||||
output: {},
|
||||
factory() {},
|
||||
}),
|
||||
}),
|
||||
).toThrow(
|
||||
"Failed to instantiate extension 'core.test', received undeclared inputs 'undeclared1' from extension 'core.test' and 'undeclared2' from extensions 'core.test', 'core.test'",
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -60,12 +60,21 @@ function resolveInputs(
|
||||
inputMap: AnyExtensionInputMap,
|
||||
attachments: Map<string, ExtensionInstance[]>,
|
||||
) {
|
||||
const undeclaredAttachments = Array.from(attachments.keys()).filter(
|
||||
name => inputMap[name] === undefined,
|
||||
const undeclaredAttachments = Array.from(attachments.entries()).filter(
|
||||
([inputName]) => inputMap[inputName] === undefined,
|
||||
);
|
||||
if (undeclaredAttachments.length > 0) {
|
||||
throw new Error(
|
||||
`received undeclared input(s) '${undeclaredAttachments.join("', '")}'`,
|
||||
`received undeclared input${
|
||||
undeclaredAttachments.length > 1 ? 's' : ''
|
||||
} ${undeclaredAttachments
|
||||
.map(
|
||||
([k, exts]) =>
|
||||
`'${k}' from extension${exts.length > 1 ? 's' : ''} '${exts
|
||||
.map(e => e.id)
|
||||
.join("', '")}'`,
|
||||
)
|
||||
.join(' and ')}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user