mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #14482 from ethereum/fix-error-ids-in-format-errors
Fix error IDs in `AnalysisFramework::formatErrors()`
This commit is contained in:
commit
c50c9b2c43
@ -46,9 +46,16 @@ public:
|
|||||||
bool _colored,
|
bool _colored,
|
||||||
bool _withErrorIds
|
bool _withErrorIds
|
||||||
):
|
):
|
||||||
m_stream(_stream), m_charStreamProvider(_charStreamProvider), m_colored(_colored), m_withErrorIds(_withErrorIds)
|
m_stream(_stream),
|
||||||
|
m_charStreamProvider(_charStreamProvider),
|
||||||
|
m_colored(_colored),
|
||||||
|
m_withErrorIds(_withErrorIds)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
// WARNING: Use the xyzErrorInformation() variants over xyzExceptionInformation() when you
|
||||||
|
// do have access to an Error instance. Error is implicitly convertible to util::Exception
|
||||||
|
// but the conversion loses the error ID.
|
||||||
|
|
||||||
/// Prints source location if it is given.
|
/// Prints source location if it is given.
|
||||||
void printSourceLocation(SourceReference const& _ref);
|
void printSourceLocation(SourceReference const& _ref);
|
||||||
void printExceptionInformation(SourceReferenceExtractor::Message const& _msg);
|
void printExceptionInformation(SourceReferenceExtractor::Message const& _msg);
|
||||||
@ -61,12 +68,11 @@ public:
|
|||||||
util::Exception const& _exception,
|
util::Exception const& _exception,
|
||||||
Error::Type _type,
|
Error::Type _type,
|
||||||
CharStreamProvider const& _charStreamProvider,
|
CharStreamProvider const& _charStreamProvider,
|
||||||
bool _colored = false,
|
bool _colored = false
|
||||||
bool _withErrorIds = false
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
std::ostringstream errorOutput;
|
std::ostringstream errorOutput;
|
||||||
SourceReferenceFormatter formatter(errorOutput, _charStreamProvider, _colored, _withErrorIds);
|
SourceReferenceFormatter formatter(errorOutput, _charStreamProvider, _colored, false /* _withErrorIds */);
|
||||||
formatter.printExceptionInformation(_exception, _type);
|
formatter.printExceptionInformation(_exception, _type);
|
||||||
return errorOutput.str();
|
return errorOutput.str();
|
||||||
}
|
}
|
||||||
@ -75,26 +81,39 @@ public:
|
|||||||
util::Exception const& _exception,
|
util::Exception const& _exception,
|
||||||
Error::Severity _severity,
|
Error::Severity _severity,
|
||||||
CharStreamProvider const& _charStreamProvider,
|
CharStreamProvider const& _charStreamProvider,
|
||||||
bool _colored = false,
|
bool _colored = false
|
||||||
bool _withErrorIds = false
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
std::ostringstream errorOutput;
|
std::ostringstream errorOutput;
|
||||||
SourceReferenceFormatter formatter(errorOutput, _charStreamProvider, _colored, _withErrorIds);
|
SourceReferenceFormatter formatter(errorOutput, _charStreamProvider, _colored, false /* _withErrorIds */);
|
||||||
formatter.printExceptionInformation(_exception, _severity);
|
formatter.printExceptionInformation(_exception, _severity);
|
||||||
return errorOutput.str();
|
return errorOutput.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string formatErrorInformation(
|
static std::string formatErrorInformation(
|
||||||
Error const& _error,
|
Error const& _error,
|
||||||
CharStreamProvider const& _charStreamProvider
|
CharStreamProvider const& _charStreamProvider,
|
||||||
|
bool _colored = false,
|
||||||
|
bool _withErrorIds = false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return formatExceptionInformation(
|
std::ostringstream errorOutput;
|
||||||
_error,
|
SourceReferenceFormatter formatter(errorOutput, _charStreamProvider, _colored, _withErrorIds);
|
||||||
Error::errorSeverity(_error.type()),
|
formatter.printErrorInformation(_error);
|
||||||
_charStreamProvider
|
return errorOutput.str();
|
||||||
);
|
}
|
||||||
|
|
||||||
|
static std::string formatErrorInformation(
|
||||||
|
langutil::ErrorList const& _errors,
|
||||||
|
CharStreamProvider const& _charStreamProvider,
|
||||||
|
bool _colored = false,
|
||||||
|
bool _withErrorIds = false
|
||||||
|
)
|
||||||
|
{
|
||||||
|
std::ostringstream errorOutput;
|
||||||
|
SourceReferenceFormatter formatter(errorOutput, _charStreamProvider, _colored, _withErrorIds);
|
||||||
|
formatter.printErrorInformation(_errors);
|
||||||
|
return errorOutput.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string formatErrorInformation(Error const& _error, CharStream const& _charStream);
|
static std::string formatErrorInformation(Error const& _error, CharStream const& _charStream);
|
||||||
|
@ -38,8 +38,6 @@
|
|||||||
#include <libsolutil/StringUtils.h>
|
#include <libsolutil/StringUtils.h>
|
||||||
#include <libsolutil/Whiskers.h>
|
#include <libsolutil/Whiskers.h>
|
||||||
|
|
||||||
#include <liblangutil/SourceReferenceFormatter.h>
|
|
||||||
|
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -1486,16 +1486,13 @@ void CompilerStack::generateIR(ContractDefinition const& _contract)
|
|||||||
m_optimiserSettings,
|
m_optimiserSettings,
|
||||||
m_debugInfoSelection
|
m_debugInfoSelection
|
||||||
);
|
);
|
||||||
if (!stack.parseAndAnalyze("", compiledContract.yulIR))
|
bool yulAnalysisSuccessful = stack.parseAndAnalyze("", compiledContract.yulIR);
|
||||||
{
|
solAssert(
|
||||||
string errorMessage;
|
yulAnalysisSuccessful,
|
||||||
for (auto const& error: stack.errors())
|
compiledContract.yulIR + "\n\n"
|
||||||
errorMessage += langutil::SourceReferenceFormatter::formatErrorInformation(
|
"Invalid IR generated:\n" +
|
||||||
*error,
|
langutil::SourceReferenceFormatter::formatErrorInformation(stack.errors(), stack) + "\n"
|
||||||
stack.charStream("")
|
);
|
||||||
);
|
|
||||||
solAssert(false, compiledContract.yulIR + "\n\nInvalid IR generated:\n" + errorMessage + "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
compiledContract.yulIRAst = stack.astJson();
|
compiledContract.yulIRAst = stack.astJson();
|
||||||
stack.optimize();
|
stack.optimize();
|
||||||
|
@ -125,8 +125,7 @@ Json::Value formatErrorWithException(
|
|||||||
_exception,
|
_exception,
|
||||||
_type,
|
_type,
|
||||||
_charStreamProvider,
|
_charStreamProvider,
|
||||||
false, // colored
|
false // colored
|
||||||
false // _withErrorIds
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (string const* description = _exception.comment())
|
if (string const* description = _exception.comment())
|
||||||
|
@ -827,7 +827,7 @@ void CommandLineInterface::compile()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_hasOutput = true;
|
m_hasOutput = true;
|
||||||
formatter.printExceptionInformation(_error, Error::errorSeverity(_error.type()));
|
formatter.printErrorInformation(_error);
|
||||||
solThrow(CommandLineExecutionError, "");
|
solThrow(CommandLineExecutionError, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,15 +147,17 @@ ErrorList AnalysisFramework::expectError(std::string const& _source, bool _warni
|
|||||||
}
|
}
|
||||||
|
|
||||||
string AnalysisFramework::formatErrors(
|
string AnalysisFramework::formatErrors(
|
||||||
langutil::ErrorList _errors,
|
langutil::ErrorList const& _errors,
|
||||||
bool _colored,
|
bool _colored,
|
||||||
bool _withErrorIds
|
bool _withErrorIds
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
string message;
|
return SourceReferenceFormatter::formatErrorInformation(
|
||||||
for (auto const& error: _errors)
|
_errors,
|
||||||
message += formatError(*error, _colored, _withErrorIds);
|
*m_compiler,
|
||||||
return message;
|
_colored,
|
||||||
|
_withErrorIds
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
string AnalysisFramework::formatError(
|
string AnalysisFramework::formatError(
|
||||||
@ -164,9 +166,8 @@ string AnalysisFramework::formatError(
|
|||||||
bool _withErrorIds
|
bool _withErrorIds
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
return SourceReferenceFormatter::formatExceptionInformation(
|
return SourceReferenceFormatter::formatErrorInformation(
|
||||||
_error,
|
_error,
|
||||||
_error.type(),
|
|
||||||
*m_compiler,
|
*m_compiler,
|
||||||
_colored,
|
_colored,
|
||||||
_withErrorIds
|
_withErrorIds
|
||||||
|
@ -58,7 +58,7 @@ protected:
|
|||||||
langutil::ErrorList expectError(std::string const& _source, bool _warning = false, bool _allowMultiple = false);
|
langutil::ErrorList expectError(std::string const& _source, bool _warning = false, bool _allowMultiple = false);
|
||||||
|
|
||||||
std::string formatErrors(
|
std::string formatErrors(
|
||||||
langutil::ErrorList _errors,
|
langutil::ErrorList const& _errors,
|
||||||
bool _colored = false,
|
bool _colored = false,
|
||||||
bool _withErrorIds = false
|
bool _withErrorIds = false
|
||||||
) const;
|
) const;
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
#include <test/Common.h>
|
#include <test/Common.h>
|
||||||
#include <libsolutil/CommonIO.h>
|
#include <libsolutil/CommonIO.h>
|
||||||
#include <libsolutil/JSON.h>
|
#include <libsolutil/JSON.h>
|
||||||
#include <liblangutil/SourceReferenceFormatter.h>
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/algorithm/string/predicate.hpp>
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
@ -85,12 +85,10 @@ std::optional<Error> parseAndReturnFirstError(
|
|||||||
if (_allowWarnings && e->type() == Error::Type::Warning)
|
if (_allowWarnings && e->type() == Error::Type::Warning)
|
||||||
continue;
|
continue;
|
||||||
if (error)
|
if (error)
|
||||||
{
|
BOOST_FAIL(
|
||||||
string errors;
|
"Found more than one error:\n" +
|
||||||
for (auto const& err: stack.errors())
|
SourceReferenceFormatter::formatErrorInformation(stack.errors(), stack)
|
||||||
errors += SourceReferenceFormatter::formatErrorInformation(*err, stack);
|
);
|
||||||
BOOST_FAIL("Found more than one error:\n" + errors);
|
|
||||||
}
|
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
if (!success)
|
if (!success)
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
#include <liblangutil/DebugInfoSelection.h>
|
#include <liblangutil/DebugInfoSelection.h>
|
||||||
#include <liblangutil/ErrorReporter.h>
|
#include <liblangutil/ErrorReporter.h>
|
||||||
#include <liblangutil/Scanner.h>
|
#include <liblangutil/Scanner.h>
|
||||||
#include <liblangutil/SourceReferenceFormatter.h>
|
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include <libyul/backends/evm/ControlFlowGraphBuilder.h>
|
#include <libyul/backends/evm/ControlFlowGraphBuilder.h>
|
||||||
#include <libyul/backends/evm/StackHelpers.h>
|
#include <libyul/backends/evm/StackHelpers.h>
|
||||||
#include <libyul/Object.h>
|
#include <libyul/Object.h>
|
||||||
#include <liblangutil/SourceReferenceFormatter.h>
|
|
||||||
|
|
||||||
#include <libsolutil/AnsiColorized.h>
|
#include <libsolutil/AnsiColorized.h>
|
||||||
#include <libsolutil/Visitor.h>
|
#include <libsolutil/Visitor.h>
|
||||||
|
@ -42,11 +42,10 @@ optional<CompilerOutput> SolidityCompilationFramework::compileContract()
|
|||||||
if (m_compilerInput.debugFailure)
|
if (m_compilerInput.debugFailure)
|
||||||
{
|
{
|
||||||
cerr << "Compiling contract failed" << endl;
|
cerr << "Compiling contract failed" << endl;
|
||||||
for (auto const& error: m_compiler.errors())
|
cerr << SourceReferenceFormatter::formatErrorInformation(
|
||||||
cerr << SourceReferenceFormatter::formatErrorInformation(
|
m_compiler.errors(),
|
||||||
*error,
|
m_compiler
|
||||||
m_compiler
|
);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -77,10 +77,7 @@ DEFINE_PROTO_FUZZER(Program const& _input)
|
|||||||
Error::containsErrors(stack.errors())
|
Error::containsErrors(stack.errors())
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
SourceReferenceFormatter formatter(std::cout, stack, false, false);
|
SourceReferenceFormatter{std::cout, stack, false, false}.printErrorInformation(stack.errors());
|
||||||
|
|
||||||
for (auto const& error: stack.errors())
|
|
||||||
formatter.printExceptionInformation(*error, Error::errorSeverity(error->type()));
|
|
||||||
yulAssert(false, "Proto fuzzer generated malformed program");
|
yulAssert(false, "Proto fuzzer generated malformed program");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
#include <liblangutil/CharStream.h>
|
#include <liblangutil/CharStream.h>
|
||||||
#include <liblangutil/ErrorReporter.h>
|
#include <liblangutil/ErrorReporter.h>
|
||||||
#include <liblangutil/SourceReferenceFormatter.h>
|
|
||||||
|
|
||||||
#include <libyul/AsmAnalysis.h>
|
#include <libyul/AsmAnalysis.h>
|
||||||
#include <libyul/AsmAnalysisInfo.h>
|
#include <libyul/AsmAnalysisInfo.h>
|
||||||
|
Loading…
Reference in New Issue
Block a user