From 16276ab10b8f673fe9e4fe2a8e17bc752680ac8a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 27 Apr 2017 14:36:38 +0100 Subject: Catch assembler exceptions and throw readable Solidity exceptions --- libsolidity/interface/CompilerStack.cpp | 37 +++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'libsolidity/interface/CompilerStack.cpp') diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 6ea9ea78..05ac483d 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -657,8 +657,41 @@ void CompilerStack::compileContract( cborEncodedMetadata += toCompactBigEndian(cborEncodedMetadata.size(), 2); compiler->compileContract(_contract, _compiledContracts, cborEncodedMetadata); compiledContract.compiler = compiler; - compiledContract.object = compiler->assembledObject(); - compiledContract.runtimeObject = compiler->runtimeObject(); + + try + { + compiledContract.object = compiler->assembledObject(); + } + catch(eth::OptimizerException const&) + { + auto err = make_shared(Error::Type::InternalCompilerError); + *err << errinfo_comment("Assembly optimizer exception for bytecode"); + m_errors.push_back(std::move(err); + } + catch(eth::AssemblyException const&) + { + auto err = make_shared(Error::Type::InternalCompilerError); + *err << errinfo_comment("Assembly exception for bytecode"); + m_errors.push_back(std::move(err); + } + + try + { + compiledContract.runtimeObject = compiler->runtimeObject(); + } + catch(eth::OptimizerException const&) + { + auto err = make_shared(Error::Type::InternalCompilerError); + *err << errinfo_comment("Assembly optimizer exception for deployed bytecode"); + m_errors.push_back(std::move(err); + } + catch(eth::AssemblyException const&) + { + auto err = make_shared(Error::Type::InternalCompilerError); + *err << errinfo_comment("Assembly exception for deployed bytecode"); + m_errors.push_back(std::move(err); + } + compiledContract.onChainMetadata = onChainMetadata; _compiledContracts[compiledContract.contract] = &compiler->assembly(); -- cgit v1.2.3 From b0485e327bfe229b4193c59ea490c7fac0dae7aa Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 27 Apr 2017 16:34:57 +0100 Subject: Make assembler errors fatal --- libsolidity/interface/CompilerStack.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'libsolidity/interface/CompilerStack.cpp') diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 05ac483d..b09435a8 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -664,15 +664,11 @@ void CompilerStack::compileContract( } catch(eth::OptimizerException const&) { - auto err = make_shared(Error::Type::InternalCompilerError); - *err << errinfo_comment("Assembly optimizer exception for bytecode"); - m_errors.push_back(std::move(err); + BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Assembly optimizer exception for bytecode")); } catch(eth::AssemblyException const&) { - auto err = make_shared(Error::Type::InternalCompilerError); - *err << errinfo_comment("Assembly exception for bytecode"); - m_errors.push_back(std::move(err); + BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Assembly exception for bytecode")); } try @@ -681,15 +677,11 @@ void CompilerStack::compileContract( } catch(eth::OptimizerException const&) { - auto err = make_shared(Error::Type::InternalCompilerError); - *err << errinfo_comment("Assembly optimizer exception for deployed bytecode"); - m_errors.push_back(std::move(err); + BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Assembly optimizer exception for deployed bytecode")); } catch(eth::AssemblyException const&) { - auto err = make_shared(Error::Type::InternalCompilerError); - *err << errinfo_comment("Assembly exception for deployed bytecode"); - m_errors.push_back(std::move(err); + BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Assembly exception for deployed bytecode")); } compiledContract.onChainMetadata = onChainMetadata; -- cgit v1.2.3