diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/error-demo/error-demo.cc | 26 | ||||
-rw-r--r-- | src/libexpr/nixexpr.hh | 3 | ||||
-rw-r--r-- | src/libutil/error.cc | 48 | ||||
-rw-r--r-- | src/libutil/logging.cc | 42 | ||||
-rw-r--r-- | src/libutil/logging.hh | 4 |
5 files changed, 61 insertions, 62 deletions
diff --git a/src/error-demo/error-demo.cc b/src/error-demo/error-demo.cc index 98018ca0e..437a761c4 100644 --- a/src/error-demo/error-demo.cc +++ b/src/error-demo/error-demo.cc @@ -29,38 +29,38 @@ int main() ErrorInfo { .level = lvlInfo, .name = "Info name", .description = "Info description", - }); + }); logger->logEI( ErrorInfo { .level = lvlTalkative, .name = "Talkative name", .description = "Talkative description", - }); + }); logger->logEI( ErrorInfo { .level = lvlChatty, .name = "Chatty name", .description = "Chatty description", - }); + }); logger->logEI( ErrorInfo { .level = lvlDebug, .name = "Debug name", .description = "Debug description", - }); + }); logger->logEI( ErrorInfo { .level = lvlVomit, .name = "Vomit name", .description = "Vomit description", - }); + }); // Error in a program; no hint and no nix code. logError( ErrorInfo { .name = "name", .description = "error description", - }); + }); // Warning with name, description, and hint. // The hintfmt function makes all the substituted text yellow. @@ -68,7 +68,7 @@ int main() ErrorInfo { .name = "name", .description = "error description", .hint = hintfmt("there was a %1%", "warning"), - }); + }); // Warning with nix file, line number, column, and the lines of @@ -80,28 +80,28 @@ int main() ErrorInfo { .name = "warning name", .description = "warning description", .hint = hintfmt("this hint has %1% templated %2%!!", - "yellow", - "values"), + "yellow", + "values"), .nixCode = NixCode { .errPos = Pos(problem_file, 40, 13), .prevLineOfCode = std::nullopt, .errLineOfCode = "this is the problem line of code", .nextLineOfCode = std::nullopt - }}); + }}); // Error with previous and next lines of code. logError( ErrorInfo { .name = "error name", .description = "error description", .hint = hintfmt("this hint has %1% templated %2%!!", - "yellow", - "values"), + "yellow", + "values"), .nixCode = NixCode { .errPos = Pos(problem_file, 40, 13), .prevLineOfCode = std::optional("previous line of code"), .errLineOfCode = "this is the problem line of code", .nextLineOfCode = std::optional("next line of code"), - }}); + }}); return 0; diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 79e3f90e5..a8bae0a61 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -234,7 +234,8 @@ struct ExprLambda : Expr : pos(pos), arg(arg), matchAttrs(matchAttrs), formals(formals), body(body) { if (!arg.empty() && formals && formals->argNames.find(arg) != formals->argNames.end()) - throw ParseError("duplicate formal function argument '%1%' at %2%", arg, pos); }; + throw ParseError("duplicate formal function argument '%1%' at %2%", arg, pos); + }; void setName(Symbol & name); string showNamePos() const; COMMON_METHODS diff --git a/src/libutil/error.cc b/src/libutil/error.cc index 8f0e0aa1a..91fa1ccd8 100644 --- a/src/libutil/error.cc +++ b/src/libutil/error.cc @@ -45,17 +45,17 @@ void printCodeLines(const string &prefix, const NixCode &nixCode) // previous line of code. if (nixCode.prevLineOfCode.has_value()) { std::cout << fmt("%1% %|2$5d|| %3%", - prefix, - (nixCode.errPos.line - 1), - *nixCode.prevLineOfCode) + prefix, + (nixCode.errPos.line - 1), + *nixCode.prevLineOfCode) << std::endl; } // line of code containing the error.%2$+5d% std::cout << fmt("%1% %|2$5d|| %3%", - prefix, - (nixCode.errPos.line), - nixCode.errLineOfCode) + prefix, + (nixCode.errPos.line), + nixCode.errLineOfCode) << std::endl; // error arrows for the column range. @@ -69,17 +69,17 @@ void printCodeLines(const string &prefix, const NixCode &nixCode) std::string arrows("^"); std::cout << fmt("%1% |%2%" ANSI_RED "%3%" ANSI_NORMAL, - prefix, - spaces, - arrows) << std::endl; + prefix, + spaces, + arrows) << std::endl; } // next line of code. if (nixCode.nextLineOfCode.has_value()) { std::cout << fmt("%1% %|2$5d|| %3%", - prefix, - (nixCode.errPos.line + 1), - *nixCode.nextLineOfCode) + prefix, + (nixCode.errPos.line + 1), + *nixCode.nextLineOfCode) << std::endl; } } @@ -149,18 +149,18 @@ std::ostream& operator<<(std::ostream &out, const ErrorInfo &einfo) // divider. if (einfo.name != "") out << fmt("%1%%2%" ANSI_BLUE " --- %3% %4% %5%" ANSI_NORMAL, - prefix, - levelString, - einfo.name, - dashes, - einfo.programName.value_or("")) + prefix, + levelString, + einfo.name, + dashes, + einfo.programName.value_or("")) << std::endl; else out << fmt("%1%%2%" ANSI_BLUE " -----%3% %4%" ANSI_NORMAL, - prefix, - levelString, - dashes, - einfo.programName.value_or("")) + prefix, + levelString, + dashes, + einfo.programName.value_or("")) << std::endl; // filename. @@ -171,9 +171,9 @@ std::ostream& operator<<(std::ostream &out, const ErrorInfo &einfo) : ""; out << fmt("%1%in file: " ANSI_BLUE "%2%%3%" ANSI_NORMAL, - prefix, - einfo.nixCode->errPos.file, - eline) << std::endl; + prefix, + einfo.nixCode->errPos.file, + eline) << std::endl; out << prefix << std::endl; } else { out << fmt("%1%from command line argument", prefix) << std::endl; diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc index 4a8b98640..e1750eb2a 100644 --- a/src/libutil/logging.cc +++ b/src/libutil/logging.cc @@ -60,7 +60,7 @@ public: void logEI(const ErrorInfo & ei) override { - std::stringstream oss; + std::stringstream oss; oss << ei; log(ei.level, oss.str()); @@ -68,7 +68,7 @@ public: void startActivity(ActivityId act, Verbosity lvl, ActivityType type, const std::string & s, const Fields & fields, ActivityId parent) - override + override { if (lvl <= verbosity && !s.empty()) log(lvl, s + "..."); @@ -111,8 +111,7 @@ Activity::Activity(Logger & logger, Verbosity lvl, ActivityType type, logger.startActivity(id, lvl, type, s, fields, parent); } -struct JSONLogger : Logger -{ +struct JSONLogger : Logger { Logger & prevLogger; JSONLogger(Logger & prevLogger) : prevLogger(prevLogger) { } @@ -155,28 +154,26 @@ struct JSONLogger : Logger json["level"] = ei.level; json["msg"] = oss.str(); - // Extra things that COULD go into json. Useful? + // Extra things that COULD go into json. Useful? // TODO: decide if useful. // TODO: make a json obj that goes into json["msg"]? json["name"] = ei.name; json["description"] = ei.description; - if (ei.hint.has_value()) - { - json["hint"] = ei.hint->str(); + if (ei.hint.has_value()) { + json["hint"] = ei.hint->str(); } - if (ei.nixCode.has_value()) - { - if (ei.nixCode->errPos.line != 0) - json["line"] = ei.nixCode->errPos.line; - if (ei.nixCode->errPos.column != 0) - json["column"] = ei.nixCode->errPos.column; - if (ei.nixCode->errPos.file != "") - json["file"] = ei.nixCode->errPos.file; - if (ei.nixCode->prevLineOfCode.has_value()) - json["prevLineOfCode"] = *ei.nixCode->prevLineOfCode; - json["errLineOfCode"] = ei.nixCode->errLineOfCode; - if (ei.nixCode->nextLineOfCode.has_value()) - json["nextLineOfCode"] = *ei.nixCode->nextLineOfCode; + if (ei.nixCode.has_value()) { + if (ei.nixCode->errPos.line != 0) + json["line"] = ei.nixCode->errPos.line; + if (ei.nixCode->errPos.column != 0) + json["column"] = ei.nixCode->errPos.column; + if (ei.nixCode->errPos.file != "") + json["file"] = ei.nixCode->errPos.file; + if (ei.nixCode->prevLineOfCode.has_value()) + json["prevLineOfCode"] = *ei.nixCode->prevLineOfCode; + json["errLineOfCode"] = ei.nixCode->errLineOfCode; + if (ei.nixCode->nextLineOfCode.has_value()) + json["nextLineOfCode"] = *ei.nixCode->nextLineOfCode; } write(json); @@ -278,7 +275,8 @@ bool handleJSONLogMessage(const std::string & msg, return true; } -Activity::~Activity() { +Activity::~Activity() +{ try { logger.stopActivity(id); } catch (...) { diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh index 89fd98419..0c4980b83 100644 --- a/src/libutil/logging.hh +++ b/src/libutil/logging.hh @@ -62,12 +62,12 @@ public: virtual void logEI(const ErrorInfo &ei) = 0; - void logEI(Verbosity lvl, ErrorInfo ei) + void logEI(Verbosity lvl, ErrorInfo ei) { ei.level = lvl; logEI(ei); } - + virtual void warn(const std::string & msg); virtual void startActivity(ActivityId act, Verbosity lvl, ActivityType type, |