@kadena/kadena-cli
Version:
Kadena CLI tool to interact with the Kadena blockchain (manage keys, transactions, etc.)
54 lines • 1.99 kB
JavaScript
import { log } from './logger.js';
export class CommandError extends Error {
constructor({ errors, warnings, exitCode, args, }) {
super(`Error:\n${(warnings !== null && warnings !== void 0 ? warnings : []).join('\n')}${(errors !== null && errors !== void 0 ? errors : []).join('\n')}`);
this.exitCode = 0;
this.errors = errors !== null && errors !== void 0 ? errors : [];
this.warnings = warnings !== null && warnings !== void 0 ? warnings : [];
this.exitCode = exitCode !== null && exitCode !== void 0 ? exitCode : 0;
this.args = args;
}
}
/**
* Prints warnings and errors of a command and asserts the output type.
* Throws a CommandError if the command was not successful.
*/
export function assertCommandError(result, ora) {
if (result.status === 'error') {
if (ora)
ora.fail('Failed');
throw new CommandError({
errors: result.errors,
warnings: result.warnings,
exitCode: 1,
});
}
else if (result.status === 'partial') {
if (result.errors.length) {
log.error(`Partial Success with Errors:\n${result.errors.join('\n')}\n`);
}
if (result.warnings && result.warnings.length) {
log.warning(`Partial Success with Warnings:\n${result.warnings.join('\n')}\n`);
}
if (ora)
ora.warn('Partially Completed');
}
else {
if (result.warnings && result.warnings.length) {
log.warning(`Success with Warnings:\n${result.warnings.join('\n')}\n`);
}
if (ora)
ora.succeed('Completed');
}
}
export function printCommandError(error) {
if (error.warnings.length > 0) {
log.warning(`${error.warnings.join('\n')}`);
}
if (error.errors.length > 0) {
if (error.warnings.length > 0)
log.error('');
log.error(`${error.errors.join('\n')}`);
}
}
//# sourceMappingURL=command.util.js.map