Skip to content

Commit

Permalink
feat: improve abi coder logs (#632)
Browse files Browse the repository at this point in the history
* normalize log output for abi coder

* cs
  • Loading branch information
Cameron Manavian authored Nov 30, 2022
1 parent 9fda91a commit 58d9fa0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-ways-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/abi-coder": patch
---

improved logging and normalized data
40 changes: 32 additions & 8 deletions packages/abi-coder/src/abi-coder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,22 @@ export default class AbiCoder {

if (Array.isArray(values) && nonEmptyTypes.length !== values.length) {
if (!hasOptionTypes(types)) {
logger.throwError('Types/values length mismatch', Logger.errors.INVALID_ARGUMENT, {
count: { types: nonEmptyTypes.length, values: values.length },
value: { types, values },
});
logger.throwError(
'Types/values length mismatch during encode',
Logger.errors.INVALID_ARGUMENT,
{
count: {
types: types.length,
nonEmptyTypes: nonEmptyTypes.length,
values: values.length,
},
value: {
types,
nonEmptyTypes,
values,
},
}
);
} else {
shallowCopyValues.length = types.length;
shallowCopyValues.fill(undefined as unknown as InputValue, values.length);
Expand All @@ -145,10 +157,22 @@ export default class AbiCoder {
const nonEmptyTypes = filterEmptyParams(types);
const assertParamsMatch = (newOffset: number) => {
if (newOffset !== bytes.length) {
logger.throwError('Types/values length mismatch', Logger.errors.INVALID_ARGUMENT, {
count: { types: nonEmptyTypes.length, values: bytes.length },
value: { types: nonEmptyTypes, bytes },
});
logger.throwError(
'Types/values length mismatch during decode',
Logger.errors.INVALID_ARGUMENT,
{
count: {
types: types.length,
nonEmptyTypes: nonEmptyTypes.length,
values: bytes.length,
},
value: {
types,
nonEmptyTypes,
values: bytes,
},
}
);
}
};

Expand Down

0 comments on commit 58d9fa0

Please sign in to comment.