diff --git a/src/app/execution/txExecution.js b/src/app/execution/txExecution.js
index 66b9b9564c..b910189ad9 100644
--- a/src/app/execution/txExecution.js
+++ b/src/app/execution/txExecution.js
@@ -1,4 +1,5 @@
'use strict'
+var yo = require('yo-yo')
module.exports = {
/**
@@ -29,5 +30,33 @@ module.exports = {
// see universaldapp.js line 660 => 700 to check possible values of txResult (error case)
callback(error, txResult)
})
+ },
+
+ /**
+ * check if the vm has errored
+ *
+ * @param {Object} txResult - the value returned by the vm
+ * @return {Object} - { error: true/false, message: DOMNode }
+ */
+ checkVMError: function (txResult) {
+ var ret = {
+ error: false,
+ message: ''
+ }
+ if (!txResult.result.vm.exceptionError) {
+ return ret
+ }
+ var error = yo` VM error: ${txResult.result.vm.exceptionError}`
+ var msg
+ if (txResult.result.vm.exceptionError === 'invalid opcode') {
+ msg = yo`
- The constructor should be payable if you send it value.
+ - The execution might have thrown.
`
+ ret.error = true
+ } else if (txResult.result.vm.exceptionError === 'out of gas') {
+ msg = yo`The transaction ran out of gas. Please increase the Gas Limit.
`
+ ret.error = true
+ }
+ ret.message = yo`${error} ${msg} Debug the transaction to get more information
`
+ return ret
}
}
diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js
index 6bdef60b09..7963b11d0f 100644
--- a/src/app/tabs/run-tab.js
+++ b/src/app/tabs/run-tab.js
@@ -304,8 +304,13 @@ function contractDropdown (appAPI, appEvents, instanceContainer) {
txExecution.createContract(data, appAPI.udapp(), (error, txResult) => {
if (!error) {
var isVM = appAPI.executionContext().isVM()
- if (isVM && alertVMErrorIfAny(txResult)) return
-
+ if (isVM) {
+ var vmError = txExecution.checkVMError(txResult)
+ if (vmError.error) {
+ modalDialogCustom.alert(vmError.message)
+ return
+ }
+ }
noInstancesText.style.display = 'none'
var address = isVM ? txResult.result.createdAddress : txResult.result.contractAddress
instanceContainer.appendChild(appAPI.udapp().renderInstance(contract, address, selectContractNames.value))
@@ -319,22 +324,6 @@ function contractDropdown (appAPI, appEvents, instanceContainer) {
})
}
- function alertVMErrorIfAny (txResult) {
- if (!txResult.result.vm.exceptionError) {
- return null
- }
- var error = yo` VM error: ${txResult.result.vm.exceptionError}`
- var msg
- if (txResult.result.vm.exceptionError === 'invalid opcode') {
- msg = yo`- The constructor should be payable if you send it value.
- - The execution might have thrown.
`
- } else if (txResult.result.vm.exceptionError === 'out of gas') {
- msg = yo`The transaction ran out of gas. Please increase the Gas Limit.
`
- }
- modalDialogCustom.alert(yo`${error} ${msg} Debug the transaction to get more information
`)
- return error + msg
- }
-
function loadFromAddress (appAPI) {
noInstancesText.style.display = 'none'
var contractNames = document.querySelector(`.${css.contractNames.classNames[0]}`)
diff --git a/src/universal-dapp.js b/src/universal-dapp.js
index a9e498af59..420c7e1e04 100644
--- a/src/universal-dapp.js
+++ b/src/universal-dapp.js
@@ -1,4 +1,4 @@
-/* global alert */
+/* global */
'use strict'
var $ = require('jquery')
@@ -13,6 +13,7 @@ var txFormat = require('./app/execution/txFormat')
var txHelper = require('./app/execution/txHelper')
var txExecution = require('./app/execution/txExecution')
var helper = require('./lib/helper')
+var modalDialogCustom = require('./app/ui/modal-dialog-custom')
// copy to copyToClipboard
const copy = require('clipboard-copy')
@@ -309,17 +310,25 @@ UniversalDApp.prototype.getCallButton = function (args) {
if (!error) {
txExecution.callFunction(args.address, data, args.funABI, self, (error, txResult) => {
if (!error) {
+ var isVM = self.executionContext.isVM()
+ if (isVM) {
+ var vmError = txExecution.checkVMError(txResult)
+ if (vmError.error) {
+ modalDialogCustom.alert(vmError.message)
+ return
+ }
+ }
if (lookupOnly) {
txFormat.decodeResponse(self.executionContext.isVM() ? txResult.result.vm.return : ethJSUtil.toBuffer(txResult.result), args.funABI, (error, decoded) => {
$outputOverride.html(error ? 'error' + error : decoded)
})
}
} else {
- alert(error)
+ modalDialogCustom.alert(error)
}
})
} else {
- alert(error)
+ modalDialogCustom.alert(error)
}
})
}
@@ -436,6 +445,17 @@ UniversalDApp.prototype.runTx = function (args, cb) {
if (!args.useCall) {
self.event.trigger('transactionExecuted', [error, args.to, args.data, false, result])
}
+ if (error) {
+ if (typeof (error) !== 'string') {
+ if (error.message) {
+ error = error.message
+ } else {
+ try {
+ error = 'error: ' + JSON.stringify(error)
+ } catch (e) {}
+ }
+ }
+ }
callback(error, result)
})
}