Merge pull request #636 from ethereum/fixAnalysisThrow

Catch exception in analysis module
pull/7/head
yann300 7 years ago committed by GitHub
commit ce1beb187c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      remix-solidity/src/analysis/staticAnalysisRunner.js

@ -16,13 +16,20 @@ staticAnalysisRunner.prototype.run = function (compilationResult, toRun, callbac
} }
staticAnalysisRunner.prototype.runWithModuleList = function (compilationResult, modules, callback) { staticAnalysisRunner.prototype.runWithModuleList = function (compilationResult, modules, callback) {
var reports = []
// Also provide convenience analysis via the AST walker. // Also provide convenience analysis via the AST walker.
var walker = new AstWalker() var walker = new AstWalker()
for (var k in compilationResult.sources) { for (var k in compilationResult.sources) {
walker.walk(compilationResult.sources[k].legacyAST, {'*': function (node) { walker.walk(compilationResult.sources[k].legacyAST, {'*': function (node) {
modules.map(function (item, i) { modules.map(function (item, i) {
if (item.mod.visit !== undefined) { if (item.mod.visit !== undefined) {
try {
item.mod.visit(node) item.mod.visit(node)
} catch (e) {
reports.push({
name: item.name, report: [{ warning: 'INTERNAL ERROR in module ' + item.name + ' ' + e.message }]
})
}
} }
}) })
return true return true
@ -31,9 +38,15 @@ staticAnalysisRunner.prototype.runWithModuleList = function (compilationResult,
// Here, modules can just collect the results from the AST walk, // Here, modules can just collect the results from the AST walk,
// but also perform new analysis. // but also perform new analysis.
var reports = modules.map(function (item, i) { reports = reports.concat(modules.map(function (item, i) {
return { name: item.name, report: item.mod.report(compilationResult) } var report = null
}) try {
report = item.mod.report(compilationResult)
} catch (e) {
report = [{ warning: 'INTERNAL ERROR in module ' + item.name + ' ' + e.message }]
}
return { name: item.name, report: report }
}))
callback(reports) callback(reports)
} }

Loading…
Cancel
Save