mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #2098 from ethereum/sourceformatter
Introduce formatExceptionInformation
This commit is contained in:
commit
bd48f181b5
@ -23,6 +23,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <functional>
|
||||
#include <libevmasm/SourceLocation.h>
|
||||
|
||||
@ -53,6 +54,16 @@ public:
|
||||
std::string const& _name,
|
||||
ScannerFromSourceNameFun const& _scannerFromSourceName
|
||||
);
|
||||
static std::string formatExceptionInformation(
|
||||
Exception const& _exception,
|
||||
std::string const& _name,
|
||||
ScannerFromSourceNameFun const& _scannerFromSourceName
|
||||
)
|
||||
{
|
||||
std::ostringstream errorOutput;
|
||||
printExceptionInformation(errorOutput, _exception, _name, _scannerFromSourceName);
|
||||
return errorOutput.str();
|
||||
}
|
||||
private:
|
||||
/// Prints source name if location is given.
|
||||
static void printSourceName(
|
||||
|
@ -50,17 +50,6 @@ extern "C" {
|
||||
typedef void (*CStyleReadFileCallback)(char const* _path, char** o_contents, char** o_error);
|
||||
}
|
||||
|
||||
string formatError(
|
||||
Exception const& _exception,
|
||||
string const& _name,
|
||||
function<Scanner const&(string const&)> const& _scannerFromSourceName
|
||||
)
|
||||
{
|
||||
ostringstream errorOutput;
|
||||
SourceReferenceFormatter::printExceptionInformation(errorOutput, _exception, _name, _scannerFromSourceName);
|
||||
return errorOutput.str();
|
||||
}
|
||||
|
||||
Json::Value functionHashes(ContractDefinition const& _contract)
|
||||
{
|
||||
Json::Value functionHashes(Json::objectValue);
|
||||
@ -170,7 +159,7 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback
|
||||
for (auto const& error: compiler.errors())
|
||||
{
|
||||
auto err = dynamic_pointer_cast<Error const>(error);
|
||||
errors.append(formatError(
|
||||
errors.append(SourceReferenceFormatter::formatExceptionInformation(
|
||||
*error,
|
||||
(err->type() == Error::Type::Warning) ? "Warning" : "Error",
|
||||
scannerFromSourceName
|
||||
@ -180,19 +169,19 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback
|
||||
}
|
||||
catch (Error const& error)
|
||||
{
|
||||
errors.append(formatError(error, error.typeName(), scannerFromSourceName));
|
||||
errors.append(SourceReferenceFormatter::formatExceptionInformation(error, error.typeName(), scannerFromSourceName));
|
||||
}
|
||||
catch (CompilerError const& exception)
|
||||
{
|
||||
errors.append(formatError(exception, "Compiler error (" + exception.lineInfo() + ")", scannerFromSourceName));
|
||||
errors.append(SourceReferenceFormatter::formatExceptionInformation(exception, "Compiler error (" + exception.lineInfo() + ")", scannerFromSourceName));
|
||||
}
|
||||
catch (InternalCompilerError const& exception)
|
||||
{
|
||||
errors.append(formatError(exception, "Internal compiler error (" + exception.lineInfo() + ")", scannerFromSourceName));
|
||||
errors.append(SourceReferenceFormatter::formatExceptionInformation(exception, "Internal compiler error (" + exception.lineInfo() + ")", scannerFromSourceName));
|
||||
}
|
||||
catch (UnimplementedFeatureError const& exception)
|
||||
{
|
||||
errors.append(formatError(exception, "Unimplemented feature (" + exception.lineInfo() + ")", scannerFromSourceName));
|
||||
errors.append(SourceReferenceFormatter::formatExceptionInformation(exception, "Unimplemented feature (" + exception.lineInfo() + ")", scannerFromSourceName));
|
||||
}
|
||||
catch (Exception const& exception)
|
||||
{
|
||||
@ -245,7 +234,7 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback
|
||||
{
|
||||
Json::Value errors(Json::arrayValue);
|
||||
for (auto const& error: formalErrors)
|
||||
errors.append(formatError(
|
||||
errors.append(SourceReferenceFormatter::formatExceptionInformation(
|
||||
*error,
|
||||
(error->type() == Error::Type::Warning) ? "Warning" : "Error",
|
||||
scannerFromSourceName
|
||||
|
Loading…
Reference in New Issue
Block a user