Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Detailed Error Handling for Invalid Struct Type Usage #278

Merged
merged 4 commits into from
Jul 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor(provable-generic.ts): move function type check after Struct …
…type check for better error handling order
MartinMinkov committed Jul 2, 2024
commit cbdbff3d9c317aa1131667cd56f2a8a374640436
14 changes: 7 additions & 7 deletions lib/provable-generic.ts
Original file line number Diff line number Diff line change
@@ -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. ` +
@@ -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]));
}