Merge pull request #760 from ethereum/revert-reason

Display reason for revert (Solidity 0.4.22 feature)
pull/3094/head
yann300 7 years ago committed by GitHub
commit 98a3dfbbf5
  1. 23
      remix-lib/src/execution/txExecution.js

@ -1,4 +1,5 @@
'use strict'
var ethJSABI = require('ethereumjs-abi')
module.exports = {
/**
@ -72,22 +73,30 @@ module.exports = {
if (!txResult.result.vm.exceptionError) {
return ret
}
var error = `VM error: ${txResult.result.vm.exceptionError}.\n`
var exceptionError = txResult.result.vm.exceptionError.error || ''
var error = `VM error: ${exceptionError}.\n`
var msg
if (txResult.result.vm.exceptionError === errorCode.INVALID_OPCODE) {
if (exceptionError === errorCode.INVALID_OPCODE) {
msg = `\t\n\tThe execution might have thrown.\n`
ret.error = true
} else if (txResult.result.vm.exceptionError === errorCode.OUT_OF_GAS) {
} else if (exceptionError === errorCode.OUT_OF_GAS) {
msg = `\tThe transaction ran out of gas. Please increase the Gas Limit.\n`
ret.error = true
} else if (txResult.result.vm.exceptionError === errorCode.REVERT) {
msg = `\tThe transaction has been reverted to the initial state.\nNote: The constructor should be payable if you send value.`
} else if (exceptionError === errorCode.REVERT) {
var returnData = txResult.result.vm.return
// It is the hash of Error(string)
if (returnData && (returnData.slice(0, 4).toString('hex') === '08c379a0')) {
var reason = ethJSABI.rawDecode(['string'], returnData.slice(4))[0]
msg = `\tThe transaction has been reverted to the initial state.\nReason provided by the contract: "${reason}".`
} else {
msg = `\tThe transaction has been reverted to the initial state.\nNote: The constructor should be payable if you send value.`
}
ret.error = true
} else if (txResult.result.vm.exceptionError === errorCode.STATIC_STATE_CHANGE) {
} else if (exceptionError === errorCode.STATIC_STATE_CHANGE) {
msg = `\tState changes is not allowed in Static Call context\n`
ret.error = true
}
ret.message = `${error}${txResult.result.vm.exceptionError}${msg}\tDebug the transaction to get more information.`
ret.message = `${error}${exceptionError}${msg}\tDebug the transaction to get more information.`
return ret
}
}

Loading…
Cancel
Save