From 74afbb04db238dfca136c5680b2e9a1ae09d73bc Mon Sep 17 00:00:00 2001 From: Aaron Cox Date: Tue, 28 Nov 2023 15:43:29 -0800 Subject: [PATCH] Adding codingPath to serializer errors --- src/serializer/decoder.ts | 6 +++++- src/serializer/encoder.ts | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/serializer/decoder.ts b/src/serializer/decoder.ts index 89e30679..a8b0bc2f 100644 --- a/src/serializer/decoder.ts +++ b/src/serializer/decoder.ts @@ -245,7 +245,11 @@ function decodeObject(value: any, type: ABI.ResolvedType, ctx: DecodingContext): return null } } - throw new Error(`Unexpectedly encountered ${value} for non-optional`) + throw new Error( + `Unexpectedly encountered ${value} for non-optional (${ctx.codingPath + .map((path) => path.field) + .join('.')})` + ) } else if (type.isArray) { if (!Array.isArray(value)) { throw new Error('Expected array') diff --git a/src/serializer/encoder.ts b/src/serializer/encoder.ts index f3590db4..d4c19bc2 100644 --- a/src/serializer/encoder.ts +++ b/src/serializer/encoder.ts @@ -179,7 +179,11 @@ export function encodeAny(value: any, type: ABI.ResolvedType, ctx: EncodingConte if (type.isExtension) { return } - throw new Error(`Found ${value} for non-optional type: ${type.typeName}`) + throw new Error( + `Found ${value} for non-optional type: ${type.typeName} (${ctx.codingPath + .map((path) => path.field) + .join('.')})` + ) } if (abiType && abiType.toABI) { // type explicitly handles encoding