Questions tagged [custom-errors]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
11 views

Do custom errors and events take up storage in Solidity?

For example, is slot 0 in this contract the uint256 x or does the custom error take up this slot? Same thing for events. contract Foo { error CustomError(); uint256 x; }
Rohan Nero's user avatar
  • 1,408
0 votes
1 answer
17 views

I am getting Struct containing a (nested) mapping cannot be constructed error

my code // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract SharedWallet { address public deployer; uint256 public totalCredits; enum TransactionStatus { Pending, Debited, ...
Rounak's user avatar
  • 1
0 votes
1 answer
24 views

How to extract the custom reverted message inside the transaction object when we're using solidity error keyword?

// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.4; error Unauthorized(); contract VendingMachine { address payable owner = payable(msg.sender); function withdraw() public { ...
0xbeny's user avatar
  • 193
2 votes
2 answers
298 views

what is the correct way to define a custom error

I am someone new to Solidity and going through the custom errors part with REVERT I have found examples where the word "ERROR" is thrown inside CONTRACT pragma solidity 0.8.18; contract ...
Diego Aaron's user avatar
0 votes
1 answer
55 views

How to display Custom Error in Frontend or custom tests?

I am using custom error like these: error BadIndexError(); revert BadIndexError(); Now, if I want to retrieve these errors how would I retrieve it in frontend? Plus, I am using custom framework for ...
Mr.SsS's user avatar
  • 415
0 votes
0 answers
78 views

TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider') ? what to do next? even my ganache is running in bg

const ethers = require("ethers"); const fs = require("fs-extra"); async function main() { const provider = new ethers.providers.JsonRpcProvider( "HTTP://127.0.0.1:7545&...
Aditya Sinha's user avatar
2 votes
1 answer
1k views

Foundry expectRevert on Custom Error with Multiple Errors

I am attempting to expectRevert on a custom error with MULTIPLE parameters by following the example in the office Foundry. I am able to get it to work with a single parameter. But as soon as I add a ...
currenthandle's user avatar
3 votes
1 answer
83 views

How to write test cases for custom errors?

I have a smart contract here that have mints NFTs and claim reward functions, and I have used custom errors instead of require error stakeNotOver(); function claimReward(uint256 stakeId) external ...
Talha Sajid Chaudhary's user avatar
2 votes
0 answers
64 views

Is there any way to bubble up custom errors without using low-level assembly?

Is there any way to bubble up custom errors without using low-level assembly? Say you have a custom error defined like this: contract For { error Unauthorized(); function reverWithError() ...
Paul Razvan Berg's user avatar
1 vote
1 answer
446 views

Is there a way to handle `abi.decode` errors?

I am trying to decode a bytes value, and while writing tests, I was trying to pass invalid values to force an error. Although I get the error missing revert data in call exception, I cannot find a way ...
BonisTech's user avatar
  • 536
1 vote
0 answers
136 views

Truffle Javascript Testing VM Exception: Custom error (could not decode)

I would like to know how to test custom error codes in my truffle javascript code. Originally I had string errors in my smart contract and the javascript tests were passing. Some time during ...
Potion's user avatar
  • 163
0 votes
0 answers
25 views

throw an error with reverting?

I'm a bit new to Solidity and am wondering if it's possible to throw an error without actually reverting? for example something along the lines of: error NotEnoughBalance(); function notify(uint256 ...
ben's user avatar
  • 13
0 votes
0 answers
88 views

Custom error message on invalid input

I have a function that requires two inputs: string and array of uint256. Here is the general structure of the function (only showing relevant part of the contract): function test(string memory _a, ...
Mat's user avatar
  • 5
0 votes
1 answer
39 views

nested mapping not working during test

I have a function that have a modifier that it must be the owner before it can cancel the order and I'm using the nested mapping that i've created for this struct as below //mapping mapping(bytes32 =&...
0xhaz's user avatar
  • 3
0 votes
2 answers
148 views

How do does the trasaction error catching work?

I am trying to understand how errors, specially custom-errors, are being handled when Ethereum transactions are reverted. From what I know, both successful and reverted transactions are mined into the ...
gagiuntoli's user avatar
1 vote
0 answers
57 views

Why openzeppeling use require instead of cursom errors?

As far as I know custom errors are more gas efficient but for example the openzeppelin contracts still use require instead of custom errors ERC20.sol function decreaseAllowance(address spender, ...
Coco's user avatar
  • 31
3 votes
1 answer
1k views

Test fails with custom error despite having "MyCustomError"

I'm writing a test that requires enterRaffle() to be reverted with MyCustomError - "Raffle__NotEnoughEthEntered" describe("enterRaffle", async function () { it("...
kihiuFrank's user avatar
0 votes
3 answers
405 views

Handling Custom Error

Why it doesn't work when I use... $ yarn hardhat --verison 2.10.2 await expect(fundMeConnectedContract.withdraw() ).to.be.revertedWith( "FundMe__NotOwner" ...
AAIIWITF's user avatar
1 vote
1 answer
343 views

Get custom error (revert reason) in web3 app

Solidity has introduced Custom Error which is cheaper than requires (as I have read). But when we get an error in web3(.js) functions like estimateGas we get Returned error: execution reverted as an ...
Prashant Prabhakar Singh's user avatar
1 vote
0 answers
262 views

How to get solidity custom errors on dApp?

I would like to get the custom error code from my dApp, however, I can't get it when the smart contract is using revert. However, I can get the error reason when the solidity contract use required. Ex....
Facundo Baez's user avatar
1 vote
1 answer
678 views

unexpected revert behaviour using custom errors in pure function

in the code below, if a revert using the custom error inside the pure function it reverts with a different error (below). If I do the same things without pure, it reverts with the custom error as ...
sola24's user avatar
  • 1,188
4 votes
4 answers
317 views

Can revert context be provided to frontend application for solidity's reverts?

There is solidity code that fails here: error InvalidCheck(uint32 _check); modifier someCheck(uint32 _check) { if (check != _check) revert InvalidCheck(check); _; } My frontend application fails ...
Reginal's user avatar
  • 75
2 votes
2 answers
110 views

What type is "MyInterface.MyCustomError" in Solidity?

I'm toying with the recently introduced custom errors. Here's a mini replica of my set up: interface MyInterface { error MyCustomError(); } I'm writing my tests in Solidity and I'd like to use ...
Paul Razvan Berg's user avatar
4 votes
1 answer
2k views

Catching custom error

I want to catch a custom defined error in my Foundry tests. Before I was using require and the following code worked: try pathRegistry.swap(WETH, LUSD, amountIn, type(uint256).max) { ...
Jan Beneš's user avatar
13 votes
3 answers
6k views

Testing for custom error reverts in hardhat

I have a custom error described as such: error AlreadyListed(address nftAddress, uint256 tokenId); And in my tests, I'd like to check to see that it's thrown: expect(await nftMarketplace.listItem(...
Patrick Collins's user avatar
4 votes
3 answers
3k views

When should I use `require` vs custom `revert` errors?

This applies only to solidity ^0.8 and onward. Let's say I have a function like this: function withdraw() external { (bool success, ) = payable(msg.sender).call{value: address(this).balance}("&...
Patrick Collins's user avatar
4 votes
3 answers
2k views

How to handle Solidity Custom Errors in ethers.js

Since Solidity v0.8.4, custom errors are supported, also in ethers.js. How can I use them in a test? Here is an example: pragma solidity 0.8.10; contract Contract { uint8 value; error ...
M. Heuer's user avatar
  • 196
12 votes
2 answers
2k views

How to bubble up a custom error when using DELEGATECALL?

Solidity v0.8.4 introduced custom errors: error Unauthorized(); Say I have contract A which delegate calls to contract B. The latter reverts with the custom error defined above. How can I bubble that ...
Paul Razvan Berg's user avatar
2 votes
1 answer
188 views

Are there well-solved patterns and practices for handling errors in Solidity?

In the spirit of Are there well-solved and simple storage patterns for Solidity?... Are there known, battle-tested practices for how to deal with errors in large Solidity codebases? It's common in ...
Paul Razvan Berg's user avatar