Merge pull request #12353 from ethereum/accessorsForExecptions

Accessors for exceptions.
This commit is contained in:
chriseth
2021-12-01 15:09:08 +01:00
committed by GitHub
7 changed files with 20 additions and 8 deletions
+10
View File
@@ -75,6 +75,16 @@ Error::Error(
*this << util::errinfo_comment(_description);
}
SourceLocation const* Error::sourceLocation() const noexcept
{
return boost::get_error_info<errinfo_sourceLocation>(*this);
}
SecondarySourceLocation const* Error::secondarySourceLocation() const noexcept
{
return boost::get_error_info<errinfo_secondarySourceLocation>(*this);
}
optional<Error::Severity> Error::severityFromString(string _input)
{
boost::algorithm::to_lower(_input);
+4 -1
View File
@@ -197,6 +197,9 @@ public:
Type type() const { return m_type; }
std::string const& typeName() const { return m_typeName; }
SourceLocation const* sourceLocation() const noexcept;
SecondarySourceLocation const* secondarySourceLocation() const noexcept;
/// helper functions
static Error const* containsErrorOfType(ErrorList const& _list, Error::Type _type)
{
@@ -206,7 +209,7 @@ public:
return nullptr;
}
static Severity errorSeverity(Type _type)
static constexpr Severity errorSeverity(Type _type)
{
if (_type == Type::Info)
return Severity::Info;
+1 -1
View File
@@ -129,7 +129,7 @@ Json::Value formatErrorWithException(
_charStreamProvider
);
if (string const* description = boost::get_error_info<util::errinfo_comment>(_exception))
if (string const* description = _exception.comment())
message = ((_message.length() > 0) ? (_message + ":") : "") + *description;
else
message = _message;
-2
View File
@@ -39,8 +39,6 @@ struct Exception: virtual std::exception, virtual boost::exception
/// @returns the errinfo_comment of this exception.
std::string const* comment() const noexcept;
private:
};
/// Throws an exception with a given description and extra information about the location the
+1 -1
View File
@@ -100,7 +100,7 @@ ErrorList AnalysisFramework::filterErrors(ErrorList const& _errorList, bool _inc
for (auto const& messagePrefix: m_messagesToCut)
if (currentError->comment()->find(messagePrefix) == 0)
{
SourceLocation const* location = boost::get_error_info<errinfo_sourceLocation>(*currentError);
SourceLocation const* location = currentError->sourceLocation();
// sufficient for now, but in future we might clone the error completely, including the secondary location
newError = make_shared<Error>(
currentError->errorId(),
+3 -2
View File
@@ -118,9 +118,10 @@ void SyntaxTest::filterObtainedErrors()
{
for (auto const& currentError: filterErrors(compiler().errors(), true))
{
int locationStart = -1, locationEnd = -1;
int locationStart = -1;
int locationEnd = -1;
string sourceName;
if (auto location = boost::get_error_info<errinfo_sourceLocation>(*currentError))
if (SourceLocation const* location = currentError->sourceLocation())
{
solAssert(location->sourceName, "");
sourceName = *location->sourceName;
+1 -1
View File
@@ -54,7 +54,7 @@ void SyntaxTest::parseAndAnalyze()
int locationStart = -1;
int locationEnd = -1;
if (auto location = boost::get_error_info<errinfo_sourceLocation>(*error))
if (SourceLocation const* location = error->sourceLocation())
{
locationStart = location->start;
locationEnd = location->end;