Skip to content

Commit

Permalink
Merge pull request #278 from o1-labs/feat/inheritence-circuitvalues
Browse files Browse the repository at this point in the history
Add Detailed Error Handling for Invalid Struct Type Usage
  • Loading branch information
MartinMinkov authored Jul 5, 2024
2 parents df307f8 + cbdbff3 commit df8c87e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/provable-generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,30 @@ function createDerivers<Field>(): {

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

if (display(typeObj) === 'Struct') {
throw new 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 (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 df8c87e

Please sign in to comment.