chore: improve backend init error message

Include extension point ID and module ID in backend init error message.

Signed-off-by: Patrick Jungermann <Patrick.Jungermann@gmail.com>
This commit is contained in:
Patrick Jungermann
2024-01-16 16:21:50 +01:00
parent f090a4ce74
commit e0c18ef3b7
4 changed files with 10 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-app-api': patch
---
Include the extension point ID and the module ID in the backend init error message.
@@ -321,7 +321,7 @@ describe('BackendInitializer', () => {
})(),
);
await expect(init.start()).rejects.toThrow(
"Extension point registered for plugin 'test-a' may not be used by module for plugin 'test-b'",
"Illegal dependency: Module 'mod' for plugin 'test-b' attempted to depend on extension point 'a' for plugin 'test-a'. Extension points can only be used within their plugin's scope.",
);
});
});
@@ -55,6 +55,7 @@ export class BackendInitializer {
async #getInitDeps(
deps: { [name: string]: ServiceOrExtensionPoint },
pluginId: string,
moduleId?: string,
) {
const result = new Map<string, unknown>();
const missingRefs = new Set<ServiceOrExtensionPoint>();
@@ -64,7 +65,7 @@ export class BackendInitializer {
if (ep) {
if (ep.pluginId !== pluginId) {
throw new Error(
`Extension point registered for plugin '${ep.pluginId}' may not be used by module for plugin '${pluginId}'`,
`Illegal dependency: Module '${moduleId}' for plugin '${pluginId}' attempted to depend on extension point '${ref.id}' for plugin '${ep.pluginId}'. Extension points can only be used within their plugin's scope.`,
);
}
result.set(name, ep.impl);
@@ -260,6 +261,7 @@ export class BackendInitializer {
const moduleDeps = await this.#getInitDeps(
moduleInit.init.deps,
pluginId,
moduleId,
);
await moduleInit.init.func(moduleDeps).catch(error => {
throw new ForwardedError(
@@ -307,7 +307,7 @@ describe('TestBackend', () => {
],
}),
).rejects.toThrow(
"Extension point registered for plugin 'testA' may not be used by module for plugin 'testB'",
"Illegal dependency: Module 'test' for plugin 'testB' attempted to depend on extension point 'a' for plugin 'testA'. Extension points can only be used within their plugin's scope.",
);
});