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
15 changes: 15 additions & 0 deletions lib/provable-generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,21 @@ function createDerivers<Field>(): {
if (!complexTypes.has(typeof typeObj))
throw Error(`provable: unsupported type "${typeObj}"`);

if (display(typeObj) === 'Struct')
mitschabaude marked this conversation as resolved.
Show resolved Hide resolved
throw Error(
`provable: cannot run check() on 'Struct' type. ` +
`Instead of using 'Struct' directly, extend 'Struct' to create a specific type.\n\n` +
`Example:\n` +
`// Incorrect Usage:\n` +
`class MyStruct extends Struct({\n` +
` fieldA: Struct, // This is incorrect\n` +
`}) {}\n\n` +
`// Correct Usage:\n` +
`class MyStruct extends Struct({\n` +
` fieldA: MySpecificStruct, // Use the specific struct type\n` +
`}) {}\n`
);

if (Array.isArray(typeObj))
return typeObj.forEach((t, i) => check(t, obj[i]));

Expand Down
Loading