Skip to content

Commit

Permalink
Treat util::Error as unexpected outside of codegen
Browse files Browse the repository at this point in the history
- In analysis we use an error reporter and never just throw util::Error. We do it in one case in the codegen (CodeGenerationError) but outside of that case this should not be treated as a proper way to report an error.
- Now such errors will be treated as unexpected. They're bugs that should be fixed.
  • Loading branch information
cameel committed Jun 13, 2024
1 parent 7377881 commit 114d706
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 22 deletions.
6 changes: 4 additions & 2 deletions libsolidity/interface/CompilerStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,10 @@ bool CompilerStack::compile(State _stopAfter)
}
catch (Error const& _error)
{
if (_error.type() != Error::Type::CodeGenerationError)
throw;
// Since codegen has no access to the error reporter, the only way for it to
// report an error is to throw. In most cases it uses dedicated exceptions,
// but CodeGenerationError is one case where someone decided to just throw Error.
solAssert(_error.type() == Error::Type::CodeGenerationError);
m_errorReporter.error(_error.errorId(), _error.type(), SourceLocation(), _error.what());
return false;
}
Expand Down
11 changes: 0 additions & 11 deletions libsolidity/interface/StandardCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1360,17 +1360,6 @@ Json StandardCompiler::compileSolidity(StandardCompiler::InputsAndSettings _inpu
));
}
}
/// This is only thrown in a very few locations.
catch (Error const& _error)
{
errors.emplace_back(formatErrorWithException(
compilerStack,
_error,
_error.type(),
"general",
"Uncaught error: "
));
}
catch (CompilerError const& _exception)
{
errors.emplace_back(formatErrorWithException(
Expand Down
6 changes: 0 additions & 6 deletions solc/CommandLineInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,12 +915,6 @@ void CommandLineInterface::compile()
);
solThrow(CommandLineExecutionError, "");
}
catch (Error const& _error)
{
m_hasOutput = true;
formatter.printErrorInformation(_error);
solThrow(CommandLineExecutionError, "");
}
}

void CommandLineInterface::handleCombinedJSON()
Expand Down
3 changes: 0 additions & 3 deletions test/tools/fuzzer_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ void FuzzerUtil::testCompiler(
{
compiler.compile();
}
catch (Error const&)
{
}
catch (UnimplementedFeatureError const&)
{
}
Expand Down

0 comments on commit 114d706

Please sign in to comment.