aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/error.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-01-21 00:55:59 +0100
committerEelco Dolstra <edolstra@gmail.com>2021-01-21 11:02:09 +0100
commit55849e153e4b28d03bfca1738c415c438c60f9f6 (patch)
treedb605ef5db346bc27a0bcfc7479f78e93d23b48f /src/libutil/error.cc
parent40608342cb3772a6d2a6c125cc2237b97c028ab4 (diff)
Change error position formatting
It's now at /home/eelco/Dev/nixpkgs/pkgs/applications/misc/hello/default.nix:7:7: instead of at: (7:7) in file: /home/eelco/Dev/nixpkgs/pkgs/applications/misc/hello/default.nix The new format is more standard and clickable.
Diffstat (limited to 'src/libutil/error.cc')
-rw-r--r--src/libutil/error.cc22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/libutil/error.cc b/src/libutil/error.cc
index ddeb5412a..5d570a75e 100644
--- a/src/libutil/error.cc
+++ b/src/libutil/error.cc
@@ -43,9 +43,9 @@ string showErrPos(const ErrPos & errPos)
{
if (errPos.line > 0) {
if (errPos.column > 0) {
- return fmt("(%1%:%2%)", errPos.line, errPos.column);
+ return fmt("%d:%d", errPos.line, errPos.column);
} else {
- return fmt("(%1%)", errPos.line);
+ return fmt("%d", errPos.line);
}
}
else {
@@ -178,24 +178,20 @@ void printCodeLines(std::ostream & out,
}
}
-void printAtPos(const string & prefix, const ErrPos & pos, std::ostream & out)
+void printAtPos(const ErrPos & pos, std::ostream & out)
{
- if (pos)
- {
+ if (pos) {
switch (pos.origin) {
case foFile: {
- out << prefix << ANSI_BLUE << "at: " << ANSI_YELLOW << showErrPos(pos) <<
- ANSI_BLUE << " in file: " << ANSI_NORMAL << pos.file;
+ out << fmt(ANSI_BLUE "at " ANSI_YELLOW "%s:%s" ANSI_NORMAL ":", pos.file, showErrPos(pos));
break;
}
case foString: {
- out << prefix << ANSI_BLUE << "at: " << ANSI_YELLOW << showErrPos(pos) <<
- ANSI_BLUE << " from string" << ANSI_NORMAL;
+ out << fmt(ANSI_BLUE "at " ANSI_YELLOW "«string»:%s" ANSI_NORMAL ":", showErrPos(pos));
break;
}
case foStdin: {
- out << prefix << ANSI_BLUE << "at: " << ANSI_YELLOW << showErrPos(pos) <<
- ANSI_BLUE << " from stdin" << ANSI_NORMAL;
+ out << fmt(ANSI_BLUE "at " ANSI_YELLOW "«stdin»:%s" ANSI_NORMAL ":", showErrPos(pos));
break;
}
default:
@@ -272,7 +268,7 @@ std::ostream & showErrorInfo(std::ostream & out, const ErrorInfo & einfo, bool s
if (einfo.errPos.has_value() && *einfo.errPos) {
oss << "\n";
- printAtPos("", *einfo.errPos, oss);
+ printAtPos(*einfo.errPos, oss);
auto loc = getCodeLines(*einfo.errPos);
@@ -292,7 +288,7 @@ std::ostream & showErrorInfo(std::ostream & out, const ErrorInfo & einfo, bool s
if (iter->pos.has_value() && (*iter->pos)) {
auto pos = iter->pos.value();
oss << "\n";
- printAtPos("", pos, oss);
+ printAtPos(pos, oss);
auto loc = getCodeLines(pos);
if (loc.has_value()) {