Skip to content

Commit 7413a54

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 d4a1cae commit 7413a54

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
@@ -317,7 +317,23 @@ export class ApiServer {
317317
const plugin = await pluginFactory.create(pluginOptions);
318318

319319
// need to invoke the i-cactus-plugin onPluginInit functionality here before plugin registry can be used further
320-
await plugin.onPluginInit();
320+
try {
321+
await plugin.onPluginInit();
322+
} catch (error) {
323+
const fnTag = `${this.className}#instantiatePlugin`;
324+
const packageName = plugin.getPackageName();
325+
const instanceId = plugin.getInstanceId();
326+
327+
const errorMessage = `${fnTag} failed calling onPluginInit() on the plugin '${packageName}' with the instanceId '${instanceId}'`;
328+
329+
this.log.error(errorMessage, error);
330+
331+
if (error instanceof Error) {
332+
throw new RuntimeError(errorMessage, error);
333+
} else {
334+
throw new RuntimeError(errorMessage, JSON.stringify(error));
335+
}
336+
}
321337

322338
return plugin;
323339
}

0 commit comments

Comments
 (0)