SourceReferenceFormatter: Support full range of options in formatErrorInformation()

This commit is contained in:
Kamil Śliwak 2023-08-08 17:08:37 +02:00
parent b7d2c8bb0a
commit 8407c8c615
4 changed files with 35 additions and 27 deletions

View File

@ -90,14 +90,28 @@ public:
static std::string formatErrorInformation(
Error const& _error,
CharStreamProvider const& _charStreamProvider
CharStreamProvider const& _charStreamProvider,
bool _colored = false,
bool _withErrorIds = false
)
{
return formatExceptionInformation(
_error,
Error::errorSeverity(_error.type()),
_charStreamProvider
);
std::ostringstream errorOutput;
SourceReferenceFormatter formatter(errorOutput, _charStreamProvider, _colored, _withErrorIds);
formatter.printErrorInformation(_error);
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);

View File

@ -1486,16 +1486,13 @@ void CompilerStack::generateIR(ContractDefinition const& _contract)
m_optimiserSettings,
m_debugInfoSelection
);
if (!stack.parseAndAnalyze("", compiledContract.yulIR))
{
string errorMessage;
for (auto const& error: stack.errors())
errorMessage += langutil::SourceReferenceFormatter::formatErrorInformation(
*error,
stack.charStream("")
);
solAssert(false, compiledContract.yulIR + "\n\nInvalid IR generated:\n" + errorMessage + "\n");
}
bool yulAnalysisSuccessful = stack.parseAndAnalyze("", compiledContract.yulIR);
solAssert(
yulAnalysisSuccessful,
compiledContract.yulIR + "\n\n"
"Invalid IR generated:\n" +
langutil::SourceReferenceFormatter::formatErrorInformation(stack.errors(), stack) + "\n"
);
compiledContract.yulIRAst = stack.astJson();
stack.optimize();

View File

@ -85,12 +85,10 @@ std::optional<Error> parseAndReturnFirstError(
if (_allowWarnings && e->type() == Error::Type::Warning)
continue;
if (error)
{
string errors;
for (auto const& err: stack.errors())
errors += SourceReferenceFormatter::formatErrorInformation(*err, stack);
BOOST_FAIL("Found more than one error:\n" + errors);
}
BOOST_FAIL(
"Found more than one error:\n" +
SourceReferenceFormatter::formatErrorInformation(stack.errors(), stack)
);
error = e;
}
if (!success)

View File

@ -42,11 +42,10 @@ optional<CompilerOutput> SolidityCompilationFramework::compileContract()
if (m_compilerInput.debugFailure)
{
cerr << "Compiling contract failed" << endl;
for (auto const& error: m_compiler.errors())
cerr << SourceReferenceFormatter::formatErrorInformation(
*error,
m_compiler
);
cerr << SourceReferenceFormatter::formatErrorInformation(
m_compiler.errors(),
m_compiler
);
}
return {};
}