fix: getErrorMessage silently ignores viem's shortMessage (#430)
viem's BaseError extends Error, so the instanceof Error branch was firing and returning error.message before the isRecord branch could check shortMessage. Check shortMessage first inside instanceof Error so terse viem messages are shown to users instead of verbose full ones. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
d9329d70b3
commit
a8a5d1ab93
1 changed files with 3 additions and 0 deletions
|
|
@ -14,6 +14,9 @@ export function coerceString(value: unknown): string | null {
|
|||
|
||||
export function getErrorMessage(error: unknown, fallback: string): string {
|
||||
if (error instanceof Error) {
|
||||
// viem's BaseError extends Error and exposes a terse shortMessage; prefer it.
|
||||
const short = coerceString((error as Record<string, unknown>).shortMessage);
|
||||
if (short) return short;
|
||||
const msg = coerceString(error.message);
|
||||
if (msg) return msg;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue