From 8118514ca38dee83019db79029834419ec4caec9 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Wed, 26 Nov 2025 13:01:04 +0100 Subject: [PATCH] feat: prettify unexpected error Signed-off-by: David Dal Busco --- src/index.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index e85a213c..aacc688d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,5 @@ +import {nonNullish} from '@dfinity/utils'; +import {AgentError} from '@icp-sdk/core/agent'; import {hasArgs} from '@junobuild/cli-tools'; import {red} from 'kleur'; import {login, logout} from './commands/auth'; @@ -203,7 +205,21 @@ export const run = async () => { await run(); } catch (err: unknown) { console.log(`${red('An unexpected error happened 😫.')}\n`); - console.log(typeof err === 'string' ? err : err instanceof Error ? err.message : undefined); + + const prettifyError = (): string | undefined => + typeof err === 'string' + ? err + : err instanceof AgentError + ? err.code.toErrorMessage() + : err instanceof Error + ? err.message + : undefined; + + const message = prettifyError(); + if (nonNullish(message)) { + console.log(message); + } + process.exit(1); } })();