aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-09-02 02:14:00 +0800
committerchriseth <c@ethdev.com>2016-09-02 02:14:00 +0800
commit52ee47190d8af18f33eae1d9417092e9211fb153 (patch)
tree9c82d9c70f705ddfe399006897a20c34c6d44a91
parentb5d941d3d9f32193c7f9094dee20511585508f6a (diff)
downloaddexon-solidity-52ee47190d8af18f33eae1d9417092e9211fb153.tar.gz
dexon-solidity-52ee47190d8af18f33eae1d9417092e9211fb153.tar.zst
dexon-solidity-52ee47190d8af18f33eae1d9417092e9211fb153.zip
Catch more exceptions in jsonCompiler.
-rw-r--r--solc/jsonCompiler.cpp92
1 files changed, 53 insertions, 39 deletions
diff --git a/solc/jsonCompiler.cpp b/solc/jsonCompiler.cpp
index 5cdee2e2..671b8c0f 100644
--- a/solc/jsonCompiler.cpp
+++ b/solc/jsonCompiler.cpp
@@ -203,51 +203,65 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback
if (success)
{
- output["contracts"] = Json::Value(Json::objectValue);
- for (string const& contractName: compiler.contractNames())
+ try
{
- Json::Value contractData(Json::objectValue);
- contractData["interface"] = compiler.interface(contractName);
- contractData["bytecode"] = compiler.object(contractName).toHex();
- contractData["runtimeBytecode"] = compiler.runtimeObject(contractName).toHex();
- contractData["opcodes"] = solidity::disassemble(compiler.object(contractName).bytecode);
- contractData["functionHashes"] = functionHashes(compiler.contractDefinition(contractName));
- contractData["gasEstimates"] = estimateGas(compiler, contractName);
- auto sourceMap = compiler.sourceMapping(contractName);
- contractData["srcmap"] = sourceMap ? *sourceMap : "";
- auto runtimeSourceMap = compiler.runtimeSourceMapping(contractName);
- contractData["srcmapRuntime"] = runtimeSourceMap ? *runtimeSourceMap : "";
- ostringstream unused;
- contractData["assembly"] = compiler.streamAssembly(unused, contractName, _sources, true);
- output["contracts"][contractName] = contractData;
- }
+ output["contracts"] = Json::Value(Json::objectValue);
+ for (string const& contractName: compiler.contractNames())
+ {
+ Json::Value contractData(Json::objectValue);
+ contractData["interface"] = compiler.interface(contractName);
+ contractData["bytecode"] = compiler.object(contractName).toHex();
+ contractData["runtimeBytecode"] = compiler.runtimeObject(contractName).toHex();
+ contractData["opcodes"] = solidity::disassemble(compiler.object(contractName).bytecode);
+ contractData["functionHashes"] = functionHashes(compiler.contractDefinition(contractName));
+ contractData["gasEstimates"] = estimateGas(compiler, contractName);
+ auto sourceMap = compiler.sourceMapping(contractName);
+ contractData["srcmap"] = sourceMap ? *sourceMap : "";
+ auto runtimeSourceMap = compiler.runtimeSourceMapping(contractName);
+ contractData["srcmapRuntime"] = runtimeSourceMap ? *runtimeSourceMap : "";
+ ostringstream unused;
+ contractData["assembly"] = compiler.streamAssembly(unused, contractName, _sources, true);
+ output["contracts"][contractName] = contractData;
+ }
+
+ // Do not taint the internal error list
+ ErrorList formalErrors;
+ if (compiler.prepareFormalAnalysis(&formalErrors))
+ output["formal"]["why3"] = compiler.formalTranslation();
+ if (!formalErrors.empty())
+ {
+ Json::Value errors(Json::arrayValue);
+ for (auto const& error: formalErrors)
+ errors.append(formatError(
+ *error,
+ (error->type() == Error::Type::Warning) ? "Warning" : "Error",
+ scannerFromSourceName
+ ));
+ output["formal"]["errors"] = errors;
+ }
- // Do not taint the internal error list
- ErrorList formalErrors;
- if (compiler.prepareFormalAnalysis(&formalErrors))
- output["formal"]["why3"] = compiler.formalTranslation();
- if (!formalErrors.empty())
+ // Indices into this array are used to abbreviate source names in source locations.
+ output["sourceList"] = Json::Value(Json::arrayValue);
+ for (auto const& source: compiler.sourceNames())
+ output["sourceList"].append(source);
+ output["sources"] = Json::Value(Json::objectValue);
+ for (auto const& source: compiler.sourceNames())
+ output["sources"][source]["AST"] = ASTJsonConverter(compiler.ast(source), compiler.sourceIndices()).json();
+ }
+ catch (...)
{
- Json::Value errors(Json::arrayValue);
- for (auto const& error: formalErrors)
- errors.append(formatError(
- *error,
- (error->type() == Error::Type::Warning) ? "Warning" : "Error",
- scannerFromSourceName
- ));
- output["formal"]["errors"] = errors;
+ output["errors"].append("Unknown exception while generating compiler output.");
}
-
- // Indices into this array are used to abbreviate source names in source locations.
- output["sourceList"] = Json::Value(Json::arrayValue);
- for (auto const& source: compiler.sourceNames())
- output["sourceList"].append(source);
- output["sources"] = Json::Value(Json::objectValue);
- for (auto const& source: compiler.sourceNames())
- output["sources"][source]["AST"] = ASTJsonConverter(compiler.ast(source), compiler.sourceIndices()).json();
}
- return Json::FastWriter().write(output);
+ try
+ {
+ return Json::FastWriter().write(output);
+ }
+ catch (...)
+ {
+ return "{\"errors\":[\"Unknown error while generating JSON.\"]}";
+ }
}
string compileMulti(string const& _input, bool _optimize, CStyleReadFileCallback _readCallback = nullptr)