Adding codingPath to serializer errors

This commit is contained in:
Aaron Cox
2023-11-28 15:43:29 -08:00
parent 6682a3e87a
commit 74afbb04db
2 changed files with 10 additions and 2 deletions
+5 -1
View File
@@ -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')
+5 -1
View File
@@ -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