Skip to content

Commit 5017ab8

Browse files
committed
fix: fix issue 1444 enhancement with specific error-handling
Separate error handling for the onPluginInit execution within instantiatePlugin Closes: hyperledger-cacti#1444 Signed-off-by: Michael Courtin <[email protected]>
1 parent 8c87107 commit 5017ab8

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/cactus-cmd-api-server/src/main/typescript/api-server.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,23 @@ export class ApiServer {
334334
const plugin = await pluginFactory.create(pluginOptions);
335335

336336
// need to invoke the i-cactus-plugin onPluginInit functionality here before plugin registry can be used further
337-
await plugin.onPluginInit();
337+
try {
338+
await plugin.onPluginInit();
339+
} catch (error) {
340+
const fnTag = `${this.className}#instantiatePlugin`;
341+
const packageName = plugin.getPackageName();
342+
const instanceId = plugin.getInstanceId();
343+
344+
const errorMessage = `${fnTag} failed calling onPluginInit() on the plugin '${packageName}' with the instanceId '${instanceId}'`;
345+
346+
this.log.error(errorMessage, error);
347+
348+
if (error instanceof Error) {
349+
throw new RuntimeError(errorMessage, error);
350+
} else {
351+
throw new RuntimeError(errorMessage, JSON.stringify(error));
352+
}
353+
}
338354

339355
return plugin;
340356
}

0 commit comments

Comments
 (0)