backend-app-api: better error message for missing service deps
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-app-api': patch
|
||||
---
|
||||
|
||||
Updated the error message for missing service dependencies to include the plugin and module IDs.
|
||||
@@ -577,6 +577,56 @@ describe('BackendInitializer', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should reject plugins with missing dependencies', async () => {
|
||||
const init = new BackendInitializer(baseFactories);
|
||||
const ref = createServiceRef<string>({ id: 'a' });
|
||||
init.add(
|
||||
createBackendPlugin({
|
||||
pluginId: 'test',
|
||||
register(reg) {
|
||||
reg.registerInit({
|
||||
deps: { ref },
|
||||
async init() {},
|
||||
});
|
||||
},
|
||||
}),
|
||||
);
|
||||
await expect(init.start()).rejects.toThrow(
|
||||
"Service or extension point dependencies of plugin 'test' are missing for the following ref(s): serviceRef{a}",
|
||||
);
|
||||
});
|
||||
|
||||
it('should reject modules with missing dependencies', async () => {
|
||||
const init = new BackendInitializer(baseFactories);
|
||||
const ref = createServiceRef<string>({ id: 'a' });
|
||||
init.add(
|
||||
createBackendPlugin({
|
||||
pluginId: 'test',
|
||||
register(reg) {
|
||||
reg.registerInit({
|
||||
deps: {},
|
||||
async init() {},
|
||||
});
|
||||
},
|
||||
}),
|
||||
);
|
||||
init.add(
|
||||
createBackendModule({
|
||||
pluginId: 'test',
|
||||
moduleId: 'test-mod',
|
||||
register(reg) {
|
||||
reg.registerInit({
|
||||
deps: { ref },
|
||||
async init() {},
|
||||
});
|
||||
},
|
||||
}),
|
||||
);
|
||||
await expect(init.start()).rejects.toThrow(
|
||||
"Service or extension point dependencies of module 'test-mod' for plugin 'test' are missing for the following ref(s): serviceRef{a}",
|
||||
);
|
||||
});
|
||||
|
||||
it('should properly load double-default CJS modules', async () => {
|
||||
expect.assertions(3);
|
||||
|
||||
|
||||
@@ -93,8 +93,11 @@ export class BackendInitializer {
|
||||
|
||||
if (missingRefs.size > 0) {
|
||||
const missing = Array.from(missingRefs).join(', ');
|
||||
const target = moduleId
|
||||
? `module '${moduleId}' for plugin '${pluginId}'`
|
||||
: `plugin '${pluginId}'`;
|
||||
throw new Error(
|
||||
`No extension point or service available for the following ref(s): ${missing}`,
|
||||
`Service or extension point dependencies of ${target} are missing for the following ref(s): ${missing}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user