Skip to content

Commit ca9e914

Browse files
committed
chore: reduce duplicated error logging
1 parent 2449059 commit ca9e914

File tree

9 files changed

+13
-58
lines changed

9 files changed

+13
-58
lines changed

src/commands/account.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export class AccountCommand extends BaseCommand {
8989
const privateKey = PrivateKey.fromStringDer(newAccountInfo.privateKey);
9090
newAccountInfo.privateKeyRaw = privateKey.toStringRaw();
9191
} catch {
92+
// TODO should this error be thrown or just logged?
9293
this.logger.error(`failed to retrieve EVM address for accountId ${newAccountInfo.accountId}`);
9394
}
9495
}
@@ -139,8 +140,7 @@ export class AccountCommand extends BaseCommand {
139140
ctx.accountInfo.privateKey,
140141
))
141142
) {
142-
this.logger.error(`failed to update account keys for accountId ${ctx.accountInfo.accountId}`);
143-
return false;
143+
throw new SoloError(`failed to update account keys for accountId ${ctx.accountInfo.accountId}`);
144144
}
145145
} else {
146146
amount = amount || (flags.amount.definition.defaultValue as number);
@@ -153,8 +153,7 @@ export class AccountCommand extends BaseCommand {
153153

154154
if (hbarAmount > 0) {
155155
if (!(await this.transferAmountFromOperator(ctx.accountInfo.accountId, hbarAmount))) {
156-
this.logger.error(`failed to transfer amount for accountId ${ctx.accountInfo.accountId}`);
157-
return false;
156+
throw new SoloError(`failed to transfer amount for accountId ${ctx.accountInfo.accountId}`);
158157
}
159158
this.logger.debug(`sent transfer amount for account ${ctx.accountInfo.accountId}`);
160159
}
@@ -658,7 +657,6 @@ export class AccountCommand extends BaseCommand {
658657
if (!r) throw new SoloError('Error running init, expected return value to be true');
659658
})
660659
.catch(err => {
661-
self.logger.showUserError(err);
662660
throw new SoloError(`Error running init: ${err.message}`, err);
663661
});
664662
},
@@ -688,7 +686,6 @@ export class AccountCommand extends BaseCommand {
688686
if (!r) throw new SoloError('Error running create, expected return value to be true');
689687
})
690688
.catch(err => {
691-
self.logger.showUserError(err);
692689
throw new SoloError(`Error running create: ${err.message}`, err);
693690
});
694691
},
@@ -716,7 +713,6 @@ export class AccountCommand extends BaseCommand {
716713
if (!r) throw new SoloError('Error running update, expected return value to be true');
717714
})
718715
.catch(err => {
719-
self.logger.showUserError(err);
720716
throw new SoloError(`Error running update: ${err.message}`, err);
721717
});
722718
},
@@ -736,7 +732,6 @@ export class AccountCommand extends BaseCommand {
736732
if (!r) throw new SoloError('Error running get, expected return value to be true');
737733
})
738734
.catch(err => {
739-
self.logger.showUserError(err);
740735
throw new SoloError(`Error running get: ${err.message}`, err);
741736
});
742737
},

src/commands/base.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ export abstract class BaseCommand extends ShellRunner {
312312
try {
313313
await tasks.run();
314314
} catch (e: Error | any) {
315-
commandDef.parent.logger.error(`${errorString}: ${e.message}`, e);
316315
throw new SoloError(`${errorString}: ${e.message}`, e);
317316
} finally {
318317
const promises = [];
@@ -348,7 +347,6 @@ export abstract class BaseCommand extends ShellRunner {
348347
self.logger.debug(`OK: setup directory: ${dirPath}`);
349348
});
350349
} catch (e: Error | any) {
351-
this.logger.error(e);
352350
throw new SoloError(`failed to create directory: ${e.message}`, e);
353351
}
354352

src/commands/cluster/tasks.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,9 @@ export class ClusterCommandTasks {
363363

364364
getClusterInfo() {
365365
return new Task('Get cluster info', async (ctx: any, task: ListrTaskWrapper<any, any, any>) => {
366-
try {
367-
const clusterName = this.parent.getK8Factory().default().clusters().readCurrent();
368-
this.parent.logger.showUser(`Cluster Name (${clusterName})`);
369-
this.parent.logger.showUser('\n');
370-
} catch (e: Error | unknown) {
371-
this.parent.logger.showUserError(e);
372-
}
366+
const clusterName = this.parent.getK8Factory().default().clusters().readCurrent();
367+
this.parent.logger.showUser(`Cluster Name (${clusterName})`);
368+
this.parent.logger.showUser('\n');
373369
});
374370
}
375371

@@ -437,10 +433,6 @@ export class ClusterCommandTasks {
437433
);
438434
} catch (e: Error | unknown) {
439435
// if error, uninstall the chart and rethrow the error
440-
parent.logger.debug(
441-
`Error on installing ${constants.SOLO_CLUSTER_SETUP_CHART}. attempting to rollback by uninstalling the chart`,
442-
e,
443-
);
444436
try {
445437
await parent
446438
.getChartManager()
@@ -453,7 +445,7 @@ export class ClusterCommandTasks {
453445
// ignore error during uninstall since we are doing the best-effort uninstall here
454446
}
455447

456-
throw e;
448+
throw new SoloError(`Error on installing ${constants.SOLO_CLUSTER_SETUP_CHART}. attempting to rollback by uninstalling the chart`, e);
457449
}
458450

459451
if (argv.dev) {

src/commands/deployment.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,7 @@ export class DeploymentCommand extends BaseCommand {
193193
task: async (ctx, task) => {
194194
self.configManager.update(argv);
195195
self.logger.debug('Updated config with argv', {config: self.configManager.config});
196-
197196
await self.configManager.executePrompt(task, [flags.clusterRef]);
198-
199197
ctx.config = {
200198
clusterName: self.configManager.getFlag<ClusterRef>(flags.clusterRef),
201199
} as Config;
@@ -264,7 +262,6 @@ export class DeploymentCommand extends BaseCommand {
264262
if (!r) throw new SoloError('Error creating deployment, expected return value to be true');
265263
})
266264
.catch(err => {
267-
self.logger.showUserError(err);
268265
throw new SoloError(`Error creating deployment: ${err.message}`, err);
269266
});
270267
},
@@ -285,7 +282,6 @@ export class DeploymentCommand extends BaseCommand {
285282
if (!r) throw new SoloError('Error listing deployments, expected return value to be true');
286283
})
287284
.catch(err => {
288-
self.logger.showUserError(err);
289285
throw new SoloError(`Error listing deployments: ${err.message}`, err);
290286
});
291287
},

src/commands/explorer.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,7 @@ export class ExplorerCommand extends BaseCommand {
363363
await tasks.run();
364364
self.logger.debug('explorer deployment has completed');
365365
} catch (e) {
366-
const message = `Error deploying explorer: ${e.message}`;
367-
self.logger.error(message, e);
368-
throw new SoloError(message, e);
366+
throw new SoloError(`Error deploying explorer: ${e.message}`, e);
369367
} finally {
370368
await lease.release();
371369
}
@@ -500,7 +498,6 @@ export class ExplorerCommand extends BaseCommand {
500498
if (!r) throw new Error('Explorer deployment failed, expected return value to be true');
501499
})
502500
.catch(err => {
503-
self.logger.showUserError(err);
504501
throw new SoloError(`Explorer deployment failed: ${err.message}`, err);
505502
});
506503
},
@@ -528,7 +525,6 @@ export class ExplorerCommand extends BaseCommand {
528525
if (!r) throw new SoloError('Explorer destruction failed, expected return value to be true');
529526
})
530527
.catch(err => {
531-
self.logger.showUserError(err);
532528
throw new SoloError(`Explorer destruction failed: ${err.message}`, err);
533529
});
534530
},

src/commands/mirror_node.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,7 @@ export class MirrorNodeCommand extends BaseCommand {
665665
await tasks.run();
666666
self.logger.debug('mirror node deployment has completed');
667667
} catch (e) {
668-
const message = `Error deploying mirror node: ${e.message}`;
669-
self.logger.error(message, e);
670-
throw new SoloError(message, e);
668+
throw new SoloError(`Error deploying mirror node: ${e.message}`, e);
671669
} finally {
672670
await lease.release();
673671
await self.accountManager.close();
@@ -837,7 +835,6 @@ export class MirrorNodeCommand extends BaseCommand {
837835
if (!r) throw new SoloError('Error deploying mirror node, expected return value to be true');
838836
})
839837
.catch(err => {
840-
self.logger.showUserError(err);
841838
throw new SoloError(`Error deploying mirror node: ${err.message}`, err);
842839
});
843840
},
@@ -865,7 +862,6 @@ export class MirrorNodeCommand extends BaseCommand {
865862
if (!r) throw new SoloError('Error destroying mirror node, expected return value to be true');
866863
})
867864
.catch(err => {
868-
self.logger.showUserError(err);
869865
throw new SoloError(`Error destroying mirror node: ${err.message}`, err);
870866
});
871867
},

src/commands/network.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,7 @@ export class NetworkCommand extends BaseCommand {
319319

320320
await this.prepareBackupUploaderSecrets(config);
321321
} catch (e: Error | any) {
322-
const errorMessage = 'failed to create Kubernetes storage secret ';
323-
this.logger.error(errorMessage, e);
324-
throw new SoloError(errorMessage, e);
322+
throw new SoloError('Failed to create Kubernetes storage secret', e);
325323
}
326324
}
327325

@@ -1272,7 +1270,6 @@ export class NetworkCommand extends BaseCommand {
12721270
if (!r) throw new SoloError('Error deploying network, expected return value to be true');
12731271
})
12741272
.catch(err => {
1275-
self.logger.showUserError(err);
12761273
throw new SoloError(`Error deploying network: ${err.message}`, err);
12771274
});
12781275
},
@@ -1302,7 +1299,6 @@ export class NetworkCommand extends BaseCommand {
13021299
if (!r) throw new SoloError('Error destroying network, expected return value to be true');
13031300
})
13041301
.catch(err => {
1305-
self.logger.showUserError(err);
13061302
throw new SoloError(`Error destroying network: ${err.message}`, err);
13071303
});
13081304
},
@@ -1323,7 +1319,6 @@ export class NetworkCommand extends BaseCommand {
13231319
if (!r) throw new SoloError('Error refreshing network, expected return value to be true');
13241320
})
13251321
.catch(err => {
1326-
self.logger.showUserError(err);
13271322
throw new SoloError(`Error refreshing network: ${err.message}`, err);
13281323
});
13291324
},

src/commands/node/tasks.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -442,15 +442,15 @@ export class NodeCommandTasks {
442442
if (!response) {
443443
task.title = `${title} - status ${chalk.yellow('UNKNOWN')}, attempt ${chalk.blueBright(`${attempt}/${maxAttempts}`)}`;
444444
clearTimeout(timeoutId);
445-
throw new Error('empty response'); // Guard
445+
throw new SoloError('empty response'); // Guard
446446
}
447447

448448
const statusLine = response.split('\n').find(line => line.startsWith('platform_PlatformStatus'));
449449

450450
if (!statusLine) {
451451
task.title = `${title} - status ${chalk.yellow('STARTING')}, attempt: ${chalk.blueBright(`${attempt}/${maxAttempts}`)}`;
452452
clearTimeout(timeoutId);
453-
throw new Error('missing status line'); // Guard
453+
throw new SoloError('missing status line'); // Guard
454454
}
455455

456456
const statusNumber = parseInt(statusLine.split(' ').pop());
@@ -725,7 +725,6 @@ export class NodeCommandTasks {
725725
prepareUpgradeReceipt.status.toString(),
726726
);
727727
} catch (e) {
728-
self.logger.error(`Error in prepare upgrade: ${e.message}`, e);
729728
throw new SoloError(`Error in prepare upgrade: ${e.message}`, e);
730729
}
731730
});
@@ -762,7 +761,6 @@ export class NodeCommandTasks {
762761
freezeUpgradeReceipt.status.toString(),
763762
);
764763
} catch (e) {
765-
self.logger.error(`Error in freeze upgrade: ${e.message}`, e);
766764
throw new SoloError(`Error in freeze upgrade: ${e.message}`, e);
767765
}
768766
});
@@ -798,7 +796,6 @@ export class NodeCommandTasks {
798796
freezeOnlyReceipt.status.toString(),
799797
);
800798
} catch (e) {
801-
self.logger.error(`Error in sending freeze transaction: ${e.message}`, e);
802799
throw new SoloError(`Error in sending freeze transaction: ${e.message}`, e);
803800
}
804801
});
@@ -934,7 +931,7 @@ export class NodeCommandTasks {
934931
undefined,
935932
context,
936933
);
937-
} catch (_) {
934+
} catch (e: Error | any) {
938935
ctx.config.skipStop = true;
939936
}
940937
},
@@ -1649,8 +1646,6 @@ export class NodeCommandTasks {
16491646
const nodeUpdateReceipt = await txResp.getReceipt(config.nodeClient);
16501647
self.logger.debug(`NodeUpdateReceipt: ${nodeUpdateReceipt.toString()}`);
16511648
} catch (e) {
1652-
self.logger.error(`Error updating node to network: ${e.message}`, e);
1653-
self.logger.error(e.stack);
16541649
throw new SoloError(`Error updating node to network: ${e.message}`, e);
16551650
}
16561651
});
@@ -2033,7 +2028,6 @@ export class NodeCommandTasks {
20332028

20342029
this.logger.debug(`NodeUpdateReceipt: ${nodeUpdateReceipt.toString()}`);
20352030
} catch (e) {
2036-
this.logger.error(`Error deleting node from network: ${e.message}`, e);
20372031
throw new SoloError(`Error deleting node from network: ${e.message}`, e);
20382032
}
20392033
});
@@ -2057,7 +2051,6 @@ export class NodeCommandTasks {
20572051
const nodeCreateReceipt = await txResp.getReceipt(config.nodeClient);
20582052
this.logger.debug(`NodeCreateReceipt: ${nodeCreateReceipt.toString()}`);
20592053
} catch (e) {
2060-
this.logger.error(`Error adding node to network: ${e.message}`, e);
20612054
throw new SoloError(`Error adding node to network: ${e.message}`, e);
20622055
}
20632056
});

src/commands/relay.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,6 @@ export class RelayCommand extends BaseCommand {
211211

212212
const tasks = new Listr<Context>(
213213
[
214-
// {
215-
// title: 'Throw',
216-
// task: async (ctx, task) => {
217-
// throw new SoloError('test throw');
218-
// },
219-
// },
220214
{
221215
title: 'Initialize',
222216
task: async (ctx, task) => {

0 commit comments

Comments
 (0)