Crates.io | jesper |
lib.rs | jesper |
version | 0.1.0 |
source | src |
created_at | 2024-01-29 17:17:22.72668 |
updated_at | 2024-01-29 17:17:22.72668 |
description | Jasper is a simple, yet powerful, error generator for Solidity. It allows you to generate typescript errors from your Solidity code, and use them to create custom error messages. |
homepage | |
repository | |
max_upload_size | |
id | 1119174 |
size | 402,613 |
Jesper is a simple, yet powerful, error generator for Solidity. It allows you to generate typescript errors from your Solidity code, and use them to create custom error messages.
npm install jasper
Jesper automatically parses the output folder of your framework and generates a typescript file with all the errors in it. You can then import this file and use it to create custom error messages.
You can also optionally leave a message on top of the error which will add a custom message to the error.
The error arguments can also be injected into the message by using the {}
syntax.
Rules
//#Message:
{}
contract MyContract {
error ErrIsContract();
//#Message: "USDG: NotVetoCouncilMember"
error ErrNotVetoCouncilMember();
//#Message: "USDG: PermanentlyFrozen"
error ErrPermanentlyFrozen();
//#Message: "USDG: ToCannotBeUSDCReceiver"
error ToCannotBeUSDCReceiver();
//#Message: "USDG: CannotSwapZero"
error ErrCannotSwapZero();
//#Message: "Cannot send to {user}"
error ErrCannotSendToUser(address user, address sender);
//......rest of logic
}
This creates a default jesper-config.json
file in the root of your project.
jesper init
jesper gen
{
"outputFolder": "./jesper-bindings", // The folder where the generated typescript file will be placed
"typescript": true, //does nothing for now, will get JS bindings soon
"framework": "foundry", //foundry | hardhat
"contractsPath": "./contracts", //The path where the contracts are located
"excludedFiles": ["./contracts/Migrations.sol"], //Files to exclude, doesen't work yet
"extraIncludedFiles": [], //Extra files to include, doesen't work yet
"modes": ["Viem"] //Viem | EthersV5
}
Jesper will output a typescript file with all the errors in it. The file will be named jesper-bindings.ts
and will be placed in the outputFolder
specified in the config.
Another file will be generated based on the modes
specified in the config. This file will be named jesperParseError<mode>.ts
and will be placed in the outputFolder
specified in the config as well.
It exports a function called jesperParseError
which takes in error data and returns a string. This function is used to parse the error message and inject the arguments into the message.
Made by 0xSimon