Skip to content

Commit

Permalink
Adding codingPath to serializer errors (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroncox authored Jun 25, 2024
1 parent c2b8e17 commit cff9e10
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/serializer/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 5 additions & 1 deletion src/serializer/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cff9e10

Please sign in to comment.