Add error IDs to console output

This commit is contained in:
a3d4
2020-06-10 13:27:25 +02:00
parent b17915a6ba
commit 51e64fe0b1
17 changed files with 77 additions and 31 deletions
+9 -1
View File
@@ -38,7 +38,15 @@ SourceReferenceExtractor::Message SourceReferenceExtractor::extract(util::Except
for (auto const& info: secondaryLocation->infos)
secondary.emplace_back(extract(&info.second, info.first));
return Message{std::move(primary), _category, std::move(secondary)};
return Message{std::move(primary), _category, std::move(secondary), nullopt};
}
SourceReferenceExtractor::Message SourceReferenceExtractor::extract(Error const& _error)
{
string category = (_error.type() == Error::Type::Warning) ? "Warning" : "Error";
Message message = extract(_error, category);
message.errorId = _error.errorId();
return message;
}
SourceReference SourceReferenceExtractor::extract(SourceLocation const* _location, std::string message)
+5 -7
View File
@@ -16,16 +16,14 @@
*/
#pragma once
#include <liblangutil/Exceptions.h>
#include <iosfwd>
#include <optional>
#include <string>
#include <tuple>
#include <vector>
namespace solidity::util
{
struct Exception;
}
namespace solidity::langutil
{
@@ -58,8 +56,6 @@ struct SourceReference
}
};
struct SourceLocation;
namespace SourceReferenceExtractor
{
struct Message
@@ -67,9 +63,11 @@ namespace SourceReferenceExtractor
SourceReference primary;
std::string category; // "Error", "Warning", ...
std::vector<SourceReference> secondary;
std::optional<ErrorId> errorId;
};
Message extract(util::Exception const& _exception, std::string _category);
Message extract(Error const& _error);
SourceReference extract(SourceLocation const* _location, std::string message = "");
}
+1 -4
View File
@@ -80,10 +80,7 @@ void SourceReferenceFormatter::printExceptionInformation(util::Exception const&
void SourceReferenceFormatter::printErrorInformation(Error const& _error)
{
printExceptionInformation(
_error,
(_error.type() == Error::Type::Warning) ? "Warning" : "Error"
);
printExceptionInformation(SourceReferenceExtractor::extract(_error));
}
void SourceReferenceFormatter::printExceptionInformation(SourceReferenceExtractor::Message const& _msg)
@@ -151,6 +151,8 @@ void SourceReferenceFormatterHuman::printExceptionInformation(SourceReferenceExt
{
// exception header line
errorColored() << _msg.category;
if (m_withErrorIds && _msg.errorId.has_value())
errorColored() << " (" << _msg.errorId.value().error << ")";
messageColored() << ": " << _msg.primary.message << '\n';
printSourceLocation(_msg.primary);
+6 -12
View File
@@ -29,22 +29,14 @@
#include <sstream>
#include <functional>
namespace solidity::util
{
struct Exception; // forward
}
namespace solidity::langutil
{
struct SourceLocation;
struct SourceReference;
class SourceReferenceFormatterHuman: public SourceReferenceFormatter
{
public:
SourceReferenceFormatterHuman(std::ostream& _stream, bool colored):
SourceReferenceFormatter{_stream}, m_colored{colored}
SourceReferenceFormatterHuman(std::ostream& _stream, bool _colored, bool _withErrorIds):
SourceReferenceFormatter{_stream}, m_colored{_colored}, m_withErrorIds(_withErrorIds)
{}
void printSourceLocation(SourceReference const& _ref) override;
@@ -54,12 +46,13 @@ public:
static std::string formatExceptionInformation(
util::Exception const& _exception,
std::string const& _name,
bool colored = false
bool _colored = false,
bool _withErrorIds = false
)
{
std::ostringstream errorOutput;
SourceReferenceFormatterHuman formatter(errorOutput, colored);
SourceReferenceFormatterHuman formatter(errorOutput, _colored, _withErrorIds);
formatter.printExceptionInformation(_exception, _name);
return errorOutput.str();
}
@@ -75,6 +68,7 @@ private:
private:
bool m_colored;
bool m_withErrorIds;
};
}