Skip to content

Commit

Permalink
refactor(provable-generic.ts): move function type check after Struct …
Browse files Browse the repository at this point in the history
…type check for better error handling order
  • Loading branch information
MartinMinkov committed Jul 2, 2024
1 parent 18f878d commit cbdbff3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/provable-generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,6 @@ function createDerivers<Field>(): {

if (isProvable(typeObj)) return typeObj.check(obj);

if (typeof typeObj === 'function') {
throw new Error(
`provable: invalid type detected. Functions are not supported as types. ` +
`Ensure you are passing an instance of a supported type or an anonymous object.\n`
);
}

if (display(typeObj) === 'Struct') {
throw new Error(
`provable: cannot run check() on 'Struct' type. ` +
Expand All @@ -201,6 +194,13 @@ function createDerivers<Field>(): {
);
}

if (typeof typeObj === 'function') {
throw new Error(
`provable: invalid type detected. Functions are not supported as types. ` +
`Ensure you are passing an instance of a supported type or an anonymous object.\n`
);
}

// Only recurse into the object if it's an object and not a function
return Object.keys(typeObj).forEach((k) => check(typeObj[k], obj[k]));
}
Expand Down

0 comments on commit cbdbff3

Please sign in to comment.