Skip to content

Commit 727740f

Browse files
authored
Merge pull request #3470 from NomicFoundation/return-data-custom-error
Show return data of unrecognized custom errors
2 parents 6bbc14e + 23a594a commit 727740f

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

.changeset/warm-radios-cross.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hardhat": patch
3+
---
4+
5+
The full return data of unrecognized custom errors is now shown in error messages

packages/hardhat-core/src/internal/hardhat-network/stack-traces/error-inferrer.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -519,12 +519,8 @@ export class ErrorInferrer {
519519
return;
520520
}
521521

522-
let errorMessage = "reverted with an unrecognized custom error";
523-
524-
const selector = returnData.getSelector();
525-
if (selector !== undefined) {
526-
errorMessage += ` with selector ${selector}`;
527-
}
522+
const rawReturnData = returnData.value.toString("hex");
523+
let errorMessage = `reverted with an unrecognized custom error (return data: 0x${rawReturnData})`;
528524

529525
for (const customError of trace.bytecode.contract.customErrors) {
530526
if (returnData.matchesSelector(customError.selector)) {

packages/hardhat-core/src/internal/hardhat-network/stack-traces/solidity-errors.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,9 @@ function getMessageFromLastStackTraceEntry(
271271
}
272272

273273
if (!stackTraceEntry.message.isEmpty()) {
274-
const selector = stackTraceEntry.message.getSelector();
274+
const returnData = stackTraceEntry.message.value.toString("hex");
275275

276-
if (selector !== undefined) {
277-
return `VM Exception while processing transaction: reverted with an unrecognized custom error with selector ${selector}`;
278-
}
279-
280-
// this should only happen when the transaction has return data but it
281-
// has less than 4 bytes, which should be a very uncommon scenario
282-
const rawReturnData = stackTraceEntry.message.value.toString("hex");
283-
return `VM Exception while processing transaction: reverted with return data ${rawReturnData}`;
276+
return `VM Exception while processing transaction: reverted with an unrecognized custom error (return data: 0x${returnData})`;
284277
}
285278

286279
if (stackTraceEntry.isInvalidOpcodeError) {

packages/hardhat-core/test/internal/hardhat-network/provider/modules/eth/methods/sendTransaction.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ describe("Eth module", function () {
420420
from: DEFAULT_ACCOUNTS_ADDRESSES[1],
421421
data: "0x6080604052348015600f57600080fd5b506040517ffbd8bc9c00000000000000000000000000000000000000000000000000000000815260040160405180910390fdfe",
422422
},
423-
"VM Exception while processing transaction: reverted with an unrecognized custom error with selector fbd8bc9c"
423+
"VM Exception while processing transaction: reverted with an unrecognized custom error (return data: 0xfbd8bc9c)"
424424
);
425425

426426
// This deploys a contract that divides by zero in its contstructor:

0 commit comments

Comments
 (0)