|
1 | 1 | import { bytesToHex as bufferToHex } from "@nomicfoundation/ethereumjs-util";
|
2 | 2 |
|
3 |
| -import { panicErrorCodeToMessage } from "./panic-errors"; |
| 3 | +import { getMessageFromStackTraceEntry } from "@nomicfoundation/edr"; |
4 | 4 | import {
|
5 | 5 | CONSTRUCTOR_FUNCTION_NAME,
|
6 | 6 | PRECOMPILE_FUNCTION_NAME,
|
@@ -82,9 +82,7 @@ export function encodeSolidityStackTrace(
|
82 | 82 | return previousPrepareStackTrace!(error, stack);
|
83 | 83 | };
|
84 | 84 |
|
85 |
| - const msg = getMessageFromLastStackTraceEntry( |
86 |
| - stackTrace[stackTrace.length - 1] |
87 |
| - ); |
| 85 | + const msg = getMessageFromStackTraceEntry(stackTrace[stackTrace.length - 1]); |
88 | 86 |
|
89 | 87 | const solidityError = new SolidityError(
|
90 | 88 | msg !== undefined ? msg : fallbackMessage,
|
@@ -214,109 +212,6 @@ function sourceReferenceToSolidityCallsite(
|
214 | 212 | );
|
215 | 213 | }
|
216 | 214 |
|
217 |
| -function getMessageFromLastStackTraceEntry( |
218 |
| - stackTraceEntry: SolidityStackTraceEntry |
219 |
| -): string | undefined { |
220 |
| - switch (stackTraceEntry.type) { |
221 |
| - case StackTraceEntryType.PRECOMPILE_ERROR: |
222 |
| - return `Transaction reverted: call to precompile ${stackTraceEntry.precompile} failed`; |
223 |
| - |
224 |
| - case StackTraceEntryType.FUNCTION_NOT_PAYABLE_ERROR: |
225 |
| - return `Transaction reverted: non-payable function was called with value ${stackTraceEntry.value.toString( |
226 |
| - 10 |
227 |
| - )}`; |
228 |
| - |
229 |
| - case StackTraceEntryType.INVALID_PARAMS_ERROR: |
230 |
| - return `Transaction reverted: function was called with incorrect parameters`; |
231 |
| - |
232 |
| - case StackTraceEntryType.FALLBACK_NOT_PAYABLE_ERROR: |
233 |
| - return `Transaction reverted: fallback function is not payable and was called with value ${stackTraceEntry.value.toString( |
234 |
| - 10 |
235 |
| - )}`; |
236 |
| - |
237 |
| - case StackTraceEntryType.FALLBACK_NOT_PAYABLE_AND_NO_RECEIVE_ERROR: |
238 |
| - return `Transaction reverted: there's no receive function, fallback function is not payable and was called with value ${stackTraceEntry.value.toString( |
239 |
| - 10 |
240 |
| - )}`; |
241 |
| - |
242 |
| - case StackTraceEntryType.UNRECOGNIZED_FUNCTION_WITHOUT_FALLBACK_ERROR: |
243 |
| - return `Transaction reverted: function selector was not recognized and there's no fallback function`; |
244 |
| - |
245 |
| - case StackTraceEntryType.MISSING_FALLBACK_OR_RECEIVE_ERROR: |
246 |
| - return `Transaction reverted: function selector was not recognized and there's no fallback nor receive function`; |
247 |
| - |
248 |
| - case StackTraceEntryType.RETURNDATA_SIZE_ERROR: |
249 |
| - return `Transaction reverted: function returned an unexpected amount of data`; |
250 |
| - |
251 |
| - case StackTraceEntryType.NONCONTRACT_ACCOUNT_CALLED_ERROR: |
252 |
| - return `Transaction reverted: function call to a non-contract account`; |
253 |
| - |
254 |
| - case StackTraceEntryType.CALL_FAILED_ERROR: |
255 |
| - return `Transaction reverted: function call failed to execute`; |
256 |
| - |
257 |
| - case StackTraceEntryType.DIRECT_LIBRARY_CALL_ERROR: |
258 |
| - return `Transaction reverted: library was called directly`; |
259 |
| - |
260 |
| - case StackTraceEntryType.UNRECOGNIZED_CREATE_ERROR: |
261 |
| - case StackTraceEntryType.UNRECOGNIZED_CONTRACT_ERROR: |
262 |
| - if (stackTraceEntry.message.isErrorReturnData()) { |
263 |
| - return `VM Exception while processing transaction: reverted with reason string '${stackTraceEntry.message.decodeError()}'`; |
264 |
| - } |
265 |
| - |
266 |
| - if (stackTraceEntry.message.isPanicReturnData()) { |
267 |
| - const message = panicErrorCodeToMessage( |
268 |
| - stackTraceEntry.message.decodePanic() |
269 |
| - ); |
270 |
| - return `VM Exception while processing transaction: ${message}`; |
271 |
| - } |
272 |
| - |
273 |
| - if (!stackTraceEntry.message.isEmpty()) { |
274 |
| - const returnData = Buffer.from(stackTraceEntry.message.value).toString( |
275 |
| - "hex" |
276 |
| - ); |
277 |
| - |
278 |
| - return `VM Exception while processing transaction: reverted with an unrecognized custom error (return data: 0x${returnData})`; |
279 |
| - } |
280 |
| - |
281 |
| - if (stackTraceEntry.isInvalidOpcodeError) { |
282 |
| - return "VM Exception while processing transaction: invalid opcode"; |
283 |
| - } |
284 |
| - |
285 |
| - return "Transaction reverted without a reason string"; |
286 |
| - |
287 |
| - case StackTraceEntryType.REVERT_ERROR: |
288 |
| - if (stackTraceEntry.message.isErrorReturnData()) { |
289 |
| - return `VM Exception while processing transaction: reverted with reason string '${stackTraceEntry.message.decodeError()}'`; |
290 |
| - } |
291 |
| - |
292 |
| - if (stackTraceEntry.isInvalidOpcodeError) { |
293 |
| - return "VM Exception while processing transaction: invalid opcode"; |
294 |
| - } |
295 |
| - |
296 |
| - return "Transaction reverted without a reason string"; |
297 |
| - |
298 |
| - case StackTraceEntryType.PANIC_ERROR: |
299 |
| - const panicMessage = panicErrorCodeToMessage(stackTraceEntry.errorCode); |
300 |
| - return `VM Exception while processing transaction: ${panicMessage}`; |
301 |
| - |
302 |
| - case StackTraceEntryType.CUSTOM_ERROR: |
303 |
| - return `VM Exception while processing transaction: ${stackTraceEntry.message}`; |
304 |
| - |
305 |
| - case StackTraceEntryType.OTHER_EXECUTION_ERROR: |
306 |
| - // TODO: What if there was returnData? |
307 |
| - return `Transaction reverted and Hardhat couldn't infer the reason.`; |
308 |
| - |
309 |
| - case StackTraceEntryType.UNMAPPED_SOLC_0_6_3_REVERT_ERROR: |
310 |
| - return "Transaction reverted without a reason string and without a valid sourcemap provided by the compiler. Some line numbers may be off. We strongly recommend upgrading solc and always using revert reasons."; |
311 |
| - |
312 |
| - case StackTraceEntryType.CONTRACT_TOO_LARGE_ERROR: |
313 |
| - return "Transaction reverted: trying to deploy a contract whose code is too large"; |
314 |
| - |
315 |
| - case StackTraceEntryType.CONTRACT_CALL_RUN_OUT_OF_GAS_ERROR: |
316 |
| - return "Transaction reverted: contract call run out of gas and made the transaction revert"; |
317 |
| - } |
318 |
| -} |
319 |
| - |
320 | 215 | // Note: This error class MUST NOT extend ProviderError, as libraries
|
321 | 216 | // use the code property to detect if they are dealing with a JSON-RPC error,
|
322 | 217 | // and take control of errors.
|
|
0 commit comments