Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More info about unreported fatal errors #15807

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions liblangutil/ErrorReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

#include <liblangutil/ErrorReporter.h>
#include <liblangutil/SourceLocation.h>

#include <libsolutil/Exceptions.h>

#include <range/v3/algorithm/find_if.hpp>
#include <memory>

Expand Down Expand Up @@ -121,7 +124,7 @@ bool ErrorReporter::checkForExcessiveErrors(Error::Type _type)
if (m_errorCount > c_maxErrorsAllowed)
{
m_errorList.push_back(std::make_shared<Error>(4013_error, Error::Type::Warning, "There are more than 256 errors. Aborting."));
BOOST_THROW_EXCEPTION(FatalError());
solThrow(FatalError, "There are more than 256 errors. Aborting.");
}
}

Expand All @@ -131,13 +134,13 @@ bool ErrorReporter::checkForExcessiveErrors(Error::Type _type)
void ErrorReporter::fatalError(ErrorId _error, Error::Type _type, SourceLocation const& _location, SecondarySourceLocation const& _secondaryLocation, std::string const& _description)
{
error(_error, _type, _location, _secondaryLocation, _description);
BOOST_THROW_EXCEPTION(FatalError());
solThrow(FatalError, _description);
}

void ErrorReporter::fatalError(ErrorId _error, Error::Type _type, SourceLocation const& _location, std::string const& _description)
{
error(_error, _type, _location, _description);
BOOST_THROW_EXCEPTION(FatalError());
solThrow(FatalError, _description);
}

ErrorList const& ErrorReporter::errors() const
Expand Down
27 changes: 21 additions & 6 deletions libsolidity/analysis/NameAndTypeResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ bool NameAndTypeResolver::registerDeclarations(SourceUnit& _sourceUnit, ASTNode
{
DeclarationRegistrationHelper registrar(m_scopes, _sourceUnit, m_errorReporter, m_globalContext, _currentScope);
}
catch (langutil::FatalError const& error)
catch (FatalError const&)
{
solAssert(m_errorReporter.hasErrors(), "Unreported fatal error: "s + error.what());
if (!m_errorReporter.hasErrors())
{
std::cerr << "Unreported fatal error:" << std::endl;
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
solAssert(false, "Unreported fatal error.");
}
return false;
}
return true;
Expand Down Expand Up @@ -135,9 +140,14 @@ bool NameAndTypeResolver::resolveNamesAndTypes(SourceUnit& _source)
return false;
}
}
catch (langutil::FatalError const& error)
catch (FatalError const&)
{
solAssert(m_errorReporter.hasErrors(), "Unreported fatal error: "s + error.what());
if (!m_errorReporter.hasErrors())
{
std::cerr << "Unreported fatal error:" << std::endl;
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
solAssert(false, "Unreported fatal error.");
}
return false;
}
return true;
Expand All @@ -150,9 +160,14 @@ bool NameAndTypeResolver::updateDeclaration(Declaration const& _declaration)
m_scopes[nullptr]->registerDeclaration(_declaration, false, true);
solAssert(_declaration.scope() == nullptr, "Updated declaration outside global scope.");
}
catch (langutil::FatalError const& error)
catch (FatalError const&)
{
solAssert(m_errorReporter.hasErrors(), "Unreported fatal error: "s + error.what());
if (!m_errorReporter.hasErrors())
{
std::cerr << "Unreported fatal error:" << std::endl;
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
solAssert(false, "Unreported fatal error.");
}
return false;
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
solAssert(m_errorReporter.hasErrors(), "Should have errors!");
for (auto const& var: variables)
if (var && !var->annotation().type)
BOOST_THROW_EXCEPTION(FatalError());
solThrow(FatalError, "Type checker failed to determine types of all variables within the declaration.");
}

return false;
Expand Down Expand Up @@ -1377,7 +1377,7 @@ bool TypeChecker::visit(Conditional const& _conditional)
commonType = falseType;

if (!trueType && !falseType)
BOOST_THROW_EXCEPTION(FatalError());
solThrow(FatalError, "Both sides of the ternary expression have invalid types.");
else if (trueType && falseType)
{
commonType = Type::commonType(trueType, falseType);
Expand Down
18 changes: 14 additions & 4 deletions libsolidity/interface/CompilerStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,14 @@ bool CompilerStack::analyze()
else if (!analyzeLegacy(noErrors))
noErrors = false;
}
catch (FatalError const& error)
catch (FatalError const&)
{
solAssert(m_errorReporter.hasErrors(), "Unreported fatal error: "s + error.what());
if (!m_errorReporter.hasErrors())
{
std::cerr << "Unreported fatal error:" << std::endl;
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
solAssert(false, "Unreported fatal error.");
}
noErrors = false;
}
catch (UnimplementedFeatureError const& _error)
Expand Down Expand Up @@ -1316,9 +1321,14 @@ StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast)
}
}
}
catch (FatalError const& error)
catch (FatalError const&)
{
solAssert(m_errorReporter.hasErrors(), "Unreported fatal error: "s + error.what());
if (!m_errorReporter.hasErrors())
{
std::cerr << "Unreported fatal error:" << std::endl;
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
solAssert(false, "Unreported fatal error.");
}
}
return newSources;
}
Expand Down
11 changes: 8 additions & 3 deletions libsolidity/parsing/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,14 @@ ASTPointer<SourceUnit> Parser::parse(CharStream& _charStream)
solAssert(m_recursionDepth == 0, "");
return nodeFactory.createNode<SourceUnit>(findLicenseString(nodes), nodes, m_experimentalSolidityEnabledInCurrentSourceUnit);
}
catch (FatalError const& error)
catch (FatalError const&)
{
solAssert(m_errorReporter.hasErrors(), "Unreported fatal error: "s + error.what());
if (!m_errorReporter.hasErrors())
{
std::cerr << "Unreported fatal error:" << std::endl;
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
solAssert(false, "Unreported fatal error.");
}
return nullptr;
}
}
Expand Down Expand Up @@ -1475,7 +1480,7 @@ ASTPointer<InlineAssembly> Parser::parseInlineAssembly(ASTPointer<ASTString> con
yul::Parser asmParser(m_errorReporter, dialect);
std::shared_ptr<yul::AST> ast = asmParser.parseInline(m_scanner);
if (ast == nullptr)
BOOST_THROW_EXCEPTION(FatalError());
solThrow(FatalError, "Failed to parse inline assembly.");

location.end = nativeLocationOf(ast->root()).end;
return std::make_shared<InlineAssembly>(nextID(), location, _docString, dialect, std::move(flags), ast);
Expand Down
9 changes: 7 additions & 2 deletions libyul/AsmAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,18 @@ bool AsmAnalyzer::analyze(Block const& _block)

(*this)(_block);
}
catch (FatalError const& error)
catch (FatalError const&)
{
// NOTE: There's a cap on the number of reported errors, but watcher.ok() will work fine even if
// we exceed it because the reporter keeps counting (it just stops adding errors to the list).
// Note also that fact of exceeding the cap triggers a FatalError so one can get thrown even
// if we don't make any of our errors fatal.
yulAssert(!watcher.ok(), "Unreported fatal error: "s + error.what());
if (watcher.ok())
{
std::cerr << "Unreported fatal error:" << std::endl;
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
yulAssert(false, "Unreported fatal error.");
}
}
return watcher.ok();
}
Expand Down
9 changes: 7 additions & 2 deletions libyul/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,14 @@ std::unique_ptr<AST> Parser::parseInline(std::shared_ptr<Scanner> const& _scanne
fetchDebugDataFromComment();
return std::make_unique<AST>(m_dialect, parseBlock());
}
catch (FatalError const& error)
catch (FatalError const&)
{
yulAssert(m_errorReporter.hasErrors(), "Unreported fatal error: "s + error.what());
if (!m_errorReporter.hasErrors())
{
std::cerr << "Unreported fatal error:" << std::endl;
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
yulAssert(false, "Unreported fatal error.");
}
}

return nullptr;
Expand Down
9 changes: 7 additions & 2 deletions libyul/ObjectParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,14 @@ std::shared_ptr<Object> ObjectParser::parse(std::shared_ptr<Scanner> const& _sca
expectToken(Token::EOS);
return object;
}
catch (FatalError const& error)
catch (FatalError const&)
{
yulAssert(m_errorReporter.hasErrors(), "Unreported fatal error: "s + error.what());
if (!m_errorReporter.hasErrors())
{
std::cerr << "Unreported fatal error:" << std::endl;
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
yulAssert(false, "Unreported fatal error.");
}
}
return nullptr;
}
Expand Down