From c8cea2c4afc0e189aa2d0bd852111c9841fc9b2c Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 6 Jul 2021 15:19:07 +0200 Subject: [PATCH] manage several edge case: - some inputs parameters can have a name, other not. - when no devdoc is defined, the devdoc property is still defined but the 'error' inside it is not defined --- libs/remix-lib/src/execution/txExecution.ts | 32 +++++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/libs/remix-lib/src/execution/txExecution.ts b/libs/remix-lib/src/execution/txExecution.ts index 792175a48c..a816a1f91f 100644 --- a/libs/remix-lib/src/execution/txExecution.ts +++ b/libs/remix-lib/src/execution/txExecution.ts @@ -112,18 +112,32 @@ export function checkVMError (execResult, abi, contract) { // "contract" reprensents the compilation result containing the NATSPEC documentation if (contract && fn.functions && Object.keys(fn.functions).length) { const functionSignature = Object.keys(fn.functions)[0] - // we check in the 'devdoc' if there's a developer documentation for this error - devdoc = contract.object.devdoc.errors[functionSignature][0] || {} - // we check in the 'userdoc' if there's an user documentation for this error - const userdoc = contract.object.userdoc.errors[functionSignature][0] || {} - if (userdoc) customError += ' : ' + (userdoc as any).notice // we append the user doc if any + // we check in the 'devdoc' if there's a developer documentation for this error + try { + devdoc = (contract.object.devdoc.errors && contract.object.devdoc.errors[functionSignature][0]) || {} + } catch (e) { + console.error(e.message) + } + // we check in the 'userdoc' if there's an user documentation for this error + try { + const userdoc = (contract.object.userdoc.errors && contract.object.userdoc.errors[functionSignature][0]) || {} + if (userdoc && (userdoc as any).notice) customError += ' : ' + (userdoc as any).notice // we append the user doc if any + } catch (e) { + console.error(e.message) + } } + let inputIndex = 0 for (const input of functionDesc.inputs) { - const v = decodedCustomErrorInputs[input.name] - decodedCustomErrorInputsClean[input.name] = { - value: v.toString ? v.toString() : v, - documentation: (devdoc as any).params[input.name] // we add the developer documentation for this input parameter if any + const inputKey = input.name || inputIndex + const v = decodedCustomErrorInputs[inputKey] + + decodedCustomErrorInputsClean[inputKey] = { + value: v.toString ? v.toString() : v + } + if (devdoc && (devdoc as any).params) { + decodedCustomErrorInputsClean[input.name].documentation = (devdoc as any).params[inputKey] // we add the developer documentation for this input parameter if any } + inputIndex++ } break }