From 7a24a5764edf728f0caa14e7aa8f832d7e6f42e3 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 24 Feb 2017 19:31:20 +0100 Subject: [PATCH 1/4] Add line info to serious exceptions. --- libdevcore/Exceptions.h | 3 +++ libsolidity/interface/Exceptions.cpp | 14 ++++++++++++++ solc/jsonCompiler.cpp | 6 +++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/libdevcore/Exceptions.h b/libdevcore/Exceptions.h index 4622774a4..37cdbed96 100644 --- a/libdevcore/Exceptions.h +++ b/libdevcore/Exceptions.h @@ -41,6 +41,9 @@ struct Exception: virtual std::exception, virtual boost::exception Exception(std::string _message = std::string()): m_message(std::move(_message)) {} const char* what() const noexcept override { return m_message.empty() ? std::exception::what() : m_message.c_str(); } + /// @returns "FileName:LineNumber" referring to the point where the exception was thrown. + std::string lineInfo() const; + private: std::string m_message; }; diff --git a/libsolidity/interface/Exceptions.cpp b/libsolidity/interface/Exceptions.cpp index 90a680b4d..41890b91a 100644 --- a/libsolidity/interface/Exceptions.cpp +++ b/libsolidity/interface/Exceptions.cpp @@ -23,6 +23,7 @@ #include #include +using namespace std; using namespace dev; using namespace dev::solidity; @@ -56,3 +57,16 @@ Error::Error(Type _type): m_type(_type) break; } } + +string Exception::lineInfo() const +{ + char const* const* file = boost::get_error_info(*this); + int const* line = boost::get_error_info(*this); + string ret; + if (file) + ret += *file; + ret += ':'; + if (line) + ret += boost::lexical_cast(*line); + return ret; +} diff --git a/solc/jsonCompiler.cpp b/solc/jsonCompiler.cpp index d761b541c..6ebd1a55a 100644 --- a/solc/jsonCompiler.cpp +++ b/solc/jsonCompiler.cpp @@ -184,15 +184,15 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback } catch (CompilerError const& exception) { - errors.append(formatError(exception, "Compiler error", scannerFromSourceName)); + errors.append(formatError(exception, "Compiler error (" + exception.lineInfo() + ")", scannerFromSourceName)); } catch (InternalCompilerError const& exception) { - errors.append(formatError(exception, "Internal compiler error", scannerFromSourceName)); + errors.append(formatError(exception, "Internal compiler error (" + exception.lineInfo() + ")", scannerFromSourceName)); } catch (UnimplementedFeatureError const& exception) { - errors.append(formatError(exception, "Unimplemented feature", scannerFromSourceName)); + errors.append(formatError(exception, "Unimplemented feature (" + exception.lineInfo() + ")", scannerFromSourceName)); } catch (Exception const& exception) { From 8877d4a7819a589d41b87e10237fa281e453a604 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 24 Feb 2017 19:31:39 +0100 Subject: [PATCH 2/4] Compiler error is not a failure. --- test/fuzzer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/fuzzer.cpp b/test/fuzzer.cpp index 85a8fe99b..f957d4edd 100644 --- a/test/fuzzer.cpp +++ b/test/fuzzer.cpp @@ -67,7 +67,6 @@ int main() for (Json::Value const& error: outputJson["errors"]) { string invalid = contains(error.asString(), vector{ - "Compiler error", "Internal compiler error", "Exception during compilation", "Unknown exception during compilation", From 9acfdb80444e94c2fe8845f796f13f8dedc49b22 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 24 Feb 2017 19:31:52 +0100 Subject: [PATCH 3/4] Print full error on failure. --- test/fuzzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fuzzer.cpp b/test/fuzzer.cpp index f957d4edd..410313c5c 100644 --- a/test/fuzzer.cpp +++ b/test/fuzzer.cpp @@ -77,7 +77,7 @@ int main() }); if (!invalid.empty()) { - cout << "Invalid error: \"" << invalid << "\"" << endl; + cout << "Invalid error: \"" << error.asString() << "\"" << endl; abort(); } } From 41360ccd57997edfd6807c75a33f4dbc4b65558b Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 24 Feb 2017 19:33:05 +0100 Subject: [PATCH 4/4] Script for filtering unique failures. --- scripts/uniqueErrors.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 scripts/uniqueErrors.sh diff --git a/scripts/uniqueErrors.sh b/scripts/uniqueErrors.sh new file mode 100755 index 000000000..eee1df903 --- /dev/null +++ b/scripts/uniqueErrors.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +REPO=$(dirname $0)/.. + +echo "Finding unique failures..." +( +for x in $* +do + echo -n $x " # " + # This subshell is a workaround to prevent the shell from printing + # "Aborted" + ("$REPO"/build/test/solfuzzer < "$x" || true) 2>&1 | head -n 1 +done +) | sort -u -t'#' -k 2