Skip to content

Commit 1d26a83

Browse files
authored
Merge pull request #15807 from ethereum/better-reporting-of-unreported-fatal-errors
More info about unreported fatal errors
2 parents cff2a28 + 04605d7 commit 1d26a83

File tree

8 files changed

+72
-24
lines changed

8 files changed

+72
-24
lines changed

liblangutil/ErrorReporter.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
#include <liblangutil/ErrorReporter.h>
2525
#include <liblangutil/SourceLocation.h>
26+
27+
#include <libsolutil/Exceptions.h>
28+
2629
#include <range/v3/algorithm/find_if.hpp>
2730
#include <memory>
2831

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

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

137140
void ErrorReporter::fatalError(ErrorId _error, Error::Type _type, SourceLocation const& _location, std::string const& _description)
138141
{
139142
error(_error, _type, _location, _description);
140-
BOOST_THROW_EXCEPTION(FatalError());
143+
solThrow(FatalError, _description);
141144
}
142145

143146
ErrorList const& ErrorReporter::errors() const

libsolidity/analysis/NameAndTypeResolver.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,14 @@ bool NameAndTypeResolver::registerDeclarations(SourceUnit& _sourceUnit, ASTNode
6161
{
6262
DeclarationRegistrationHelper registrar(m_scopes, _sourceUnit, m_errorReporter, m_globalContext, _currentScope);
6363
}
64-
catch (langutil::FatalError const& error)
64+
catch (FatalError const&)
6565
{
66-
solAssert(m_errorReporter.hasErrors(), "Unreported fatal error: "s + error.what());
66+
if (!m_errorReporter.hasErrors())
67+
{
68+
std::cerr << "Unreported fatal error:" << std::endl;
69+
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
70+
solAssert(false, "Unreported fatal error.");
71+
}
6772
return false;
6873
}
6974
return true;
@@ -135,9 +140,14 @@ bool NameAndTypeResolver::resolveNamesAndTypes(SourceUnit& _source)
135140
return false;
136141
}
137142
}
138-
catch (langutil::FatalError const& error)
143+
catch (FatalError const&)
139144
{
140-
solAssert(m_errorReporter.hasErrors(), "Unreported fatal error: "s + error.what());
145+
if (!m_errorReporter.hasErrors())
146+
{
147+
std::cerr << "Unreported fatal error:" << std::endl;
148+
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
149+
solAssert(false, "Unreported fatal error.");
150+
}
141151
return false;
142152
}
143153
return true;
@@ -150,9 +160,14 @@ bool NameAndTypeResolver::updateDeclaration(Declaration const& _declaration)
150160
m_scopes[nullptr]->registerDeclaration(_declaration, false, true);
151161
solAssert(_declaration.scope() == nullptr, "Updated declaration outside global scope.");
152162
}
153-
catch (langutil::FatalError const& error)
163+
catch (FatalError const&)
154164
{
155-
solAssert(m_errorReporter.hasErrors(), "Unreported fatal error: "s + error.what());
165+
if (!m_errorReporter.hasErrors())
166+
{
167+
std::cerr << "Unreported fatal error:" << std::endl;
168+
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
169+
solAssert(false, "Unreported fatal error.");
170+
}
156171
return false;
157172
}
158173
return true;

libsolidity/analysis/TypeChecker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
13271327
solAssert(m_errorReporter.hasErrors(), "Should have errors!");
13281328
for (auto const& var: variables)
13291329
if (var && !var->annotation().type)
1330-
BOOST_THROW_EXCEPTION(FatalError());
1330+
solThrow(FatalError, "Type checker failed to determine types of all variables within the declaration.");
13311331
}
13321332

13331333
return false;
@@ -1380,7 +1380,7 @@ bool TypeChecker::visit(Conditional const& _conditional)
13801380
commonType = falseType;
13811381

13821382
if (!trueType && !falseType)
1383-
BOOST_THROW_EXCEPTION(FatalError());
1383+
solThrow(FatalError, "Both sides of the ternary expression have invalid types.");
13841384
else if (trueType && falseType)
13851385
{
13861386
commonType = Type::commonType(trueType, falseType);

libsolidity/interface/CompilerStack.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,14 @@ bool CompilerStack::analyze()
507507
else if (!analyzeLegacy(noErrors))
508508
noErrors = false;
509509
}
510-
catch (FatalError const& error)
510+
catch (FatalError const&)
511511
{
512-
solAssert(m_errorReporter.hasErrors(), "Unreported fatal error: "s + error.what());
512+
if (!m_errorReporter.hasErrors())
513+
{
514+
std::cerr << "Unreported fatal error:" << std::endl;
515+
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
516+
solAssert(false, "Unreported fatal error.");
517+
}
513518
noErrors = false;
514519
}
515520
catch (UnimplementedFeatureError const& _error)
@@ -1317,9 +1322,14 @@ StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast)
13171322
}
13181323
}
13191324
}
1320-
catch (FatalError const& error)
1325+
catch (FatalError const&)
13211326
{
1322-
solAssert(m_errorReporter.hasErrors(), "Unreported fatal error: "s + error.what());
1327+
if (!m_errorReporter.hasErrors())
1328+
{
1329+
std::cerr << "Unreported fatal error:" << std::endl;
1330+
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
1331+
solAssert(false, "Unreported fatal error.");
1332+
}
13231333
}
13241334
return newSources;
13251335
}

libsolidity/parsing/Parser.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,14 @@ ASTPointer<SourceUnit> Parser::parse(CharStream& _charStream)
176176
solAssert(m_recursionDepth == 0, "");
177177
return nodeFactory.createNode<SourceUnit>(findLicenseString(nodes), nodes, m_experimentalSolidityEnabledInCurrentSourceUnit);
178178
}
179-
catch (FatalError const& error)
179+
catch (FatalError const&)
180180
{
181-
solAssert(m_errorReporter.hasErrors(), "Unreported fatal error: "s + error.what());
181+
if (!m_errorReporter.hasErrors())
182+
{
183+
std::cerr << "Unreported fatal error:" << std::endl;
184+
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
185+
solAssert(false, "Unreported fatal error.");
186+
}
182187
return nullptr;
183188
}
184189
}
@@ -1539,7 +1544,7 @@ ASTPointer<InlineAssembly> Parser::parseInlineAssembly(ASTPointer<ASTString> con
15391544
yul::Parser asmParser(m_errorReporter, dialect);
15401545
std::shared_ptr<yul::AST> ast = asmParser.parseInline(m_scanner);
15411546
if (ast == nullptr)
1542-
BOOST_THROW_EXCEPTION(FatalError());
1547+
solThrow(FatalError, "Failed to parse inline assembly.");
15431548

15441549
location.end = nativeLocationOf(ast->root()).end;
15451550
return std::make_shared<InlineAssembly>(nextID(), location, _docString, dialect, std::move(flags), ast);

libyul/AsmAnalysis.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,18 @@ bool AsmAnalyzer::analyze(Block const& _block)
7575

7676
(*this)(_block);
7777
}
78-
catch (FatalError const& error)
78+
catch (FatalError const&)
7979
{
8080
// NOTE: There's a cap on the number of reported errors, but watcher.ok() will work fine even if
8181
// we exceed it because the reporter keeps counting (it just stops adding errors to the list).
8282
// Note also that fact of exceeding the cap triggers a FatalError so one can get thrown even
8383
// if we don't make any of our errors fatal.
84-
yulAssert(!watcher.ok(), "Unreported fatal error: "s + error.what());
84+
if (watcher.ok())
85+
{
86+
std::cerr << "Unreported fatal error:" << std::endl;
87+
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
88+
yulAssert(false, "Unreported fatal error.");
89+
}
8590
}
8691
return watcher.ok();
8792
}

libyul/AsmParser.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,14 @@ std::unique_ptr<AST> Parser::parseInline(std::shared_ptr<Scanner> const& _scanne
127127
fetchDebugDataFromComment();
128128
return std::make_unique<AST>(m_dialect, parseBlock());
129129
}
130-
catch (FatalError const& error)
130+
catch (FatalError const&)
131131
{
132-
yulAssert(m_errorReporter.hasErrors(), "Unreported fatal error: "s + error.what());
132+
if (!m_errorReporter.hasErrors())
133+
{
134+
std::cerr << "Unreported fatal error:" << std::endl;
135+
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
136+
yulAssert(false, "Unreported fatal error.");
137+
}
133138
}
134139

135140
return nullptr;

libyul/ObjectParser.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,14 @@ std::shared_ptr<Object> ObjectParser::parse(std::shared_ptr<Scanner> const& _sca
6363
expectToken(Token::EOS);
6464
return object;
6565
}
66-
catch (FatalError const& error)
66+
catch (FatalError const&)
6767
{
68-
yulAssert(m_errorReporter.hasErrors(), "Unreported fatal error: "s + error.what());
68+
if (!m_errorReporter.hasErrors())
69+
{
70+
std::cerr << "Unreported fatal error:" << std::endl;
71+
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
72+
yulAssert(false, "Unreported fatal error.");
73+
}
6974
}
7075
return nullptr;
7176
}

0 commit comments

Comments
 (0)