fix: correct TypeScript cast for shortMessage in getErrorMessage (#430)
The direct cast of Error to Record<string, unknown> is rejected by TypeScript because the types don't sufficiently overlap. Cast via unknown first to satisfy the compiler. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a8a5d1ab93
commit
fc008fb9c1
1 changed files with 1 additions and 1 deletions
|
|
@ -15,7 +15,7 @@ export function coerceString(value: unknown): string | null {
|
||||||
export function getErrorMessage(error: unknown, fallback: string): string {
|
export function getErrorMessage(error: unknown, fallback: string): string {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
// viem's BaseError extends Error and exposes a terse shortMessage; prefer it.
|
// viem's BaseError extends Error and exposes a terse shortMessage; prefer it.
|
||||||
const short = coerceString((error as Record<string, unknown>).shortMessage);
|
const short = coerceString((error as unknown as Record<string, unknown>).shortMessage);
|
||||||
if (short) return short;
|
if (short) return short;
|
||||||
const msg = coerceString(error.message);
|
const msg = coerceString(error.message);
|
||||||
if (msg) return msg;
|
if (msg) return msg;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue