aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Burdette <bburdette@gmail.com>2020-06-03 14:47:00 -0600
committerBen Burdette <bburdette@gmail.com>2020-06-03 14:47:00 -0600
commitf97576c5d91d5278155a67e2b8982d2233d4335a (patch)
treeec90ffbf510c182d66305dfee40f05dfb567e40a /src
parent156d4f8bc892baa4e25814d5f79a332994c750d1 (diff)
newline-as-prefix; no final newline in output.
Diffstat (limited to 'src')
-rw-r--r--src/libutil/error.cc73
1 files changed, 39 insertions, 34 deletions
diff --git a/src/libutil/error.cc b/src/libutil/error.cc
index 59628d875..539a7543f 100644
--- a/src/libutil/error.cc
+++ b/src/libutil/error.cc
@@ -57,20 +57,20 @@ void printCodeLines(std::ostream &out, const string &prefix, const NixCode &nixC
{
// previous line of code.
if (nixCode.prevLineOfCode.has_value()) {
- out << fmt("%1% %|2$5d|| %3%",
- prefix,
- (nixCode.errPos.line - 1),
- *nixCode.prevLineOfCode)
- << std::endl;
+ out << std::endl
+ << fmt("%1% %|2$5d|| %3%",
+ prefix,
+ (nixCode.errPos.line - 1),
+ *nixCode.prevLineOfCode);
}
if (nixCode.errLineOfCode.has_value()) {
// line of code containing the error.
- out << fmt("%1% %|2$5d|| %3%",
- prefix,
- (nixCode.errPos.line),
- *nixCode.errLineOfCode)
- << std::endl;
+ out << std::endl
+ << fmt("%1% %|2$5d|| %3%",
+ prefix,
+ (nixCode.errPos.line),
+ *nixCode.errLineOfCode);
// error arrows for the column range.
if (nixCode.errPos.column > 0) {
int start = nixCode.errPos.column;
@@ -81,20 +81,21 @@ void printCodeLines(std::ostream &out, const string &prefix, const NixCode &nixC
std::string arrows("^");
- out << fmt("%1% |%2%" ANSI_RED "%3%" ANSI_NORMAL,
- prefix,
- spaces,
- arrows) << std::endl;
+ out << std::endl
+ << fmt("%1% |%2%" ANSI_RED "%3%" ANSI_NORMAL,
+ prefix,
+ spaces,
+ arrows);
}
}
// next line of code.
if (nixCode.nextLineOfCode.has_value()) {
- out << fmt("%1% %|2$5d|| %3%",
- prefix,
- (nixCode.errPos.line + 1),
- *nixCode.nextLineOfCode)
- << std::endl;
+ out << std::endl
+ << fmt("%1% %|2$5d|| %3%",
+ prefix,
+ (nixCode.errPos.line + 1),
+ *nixCode.nextLineOfCode);
}
}
@@ -167,46 +168,50 @@ std::ostream& operator<<(std::ostream &out, const ErrorInfo &einfo)
levelString,
einfo.name,
dashes,
- einfo.programName.value_or(""))
- << std::endl;
+ einfo.programName.value_or(""));
else
out << fmt("%1%%2%" ANSI_BLUE " -----%3% %4%" ANSI_NORMAL,
prefix,
levelString,
dashes,
- einfo.programName.value_or(""))
- << std::endl;
+ einfo.programName.value_or(""));
- // filename, line, column.
+ bool nl = false; // intersperse newline between sections.
if (einfo.nixCode.has_value()) {
if (einfo.nixCode->errPos.file != "") {
- out << fmt("%1%in file: " ANSI_BLUE "%2% %3%" ANSI_NORMAL,
+ // filename, line, column.
+ out << std::endl << fmt("%1%in file: " ANSI_BLUE "%2% %3%" ANSI_NORMAL,
prefix,
einfo.nixCode->errPos.file,
- showErrPos(einfo.nixCode->errPos)) << std::endl;
- out << prefix << std::endl;
+ showErrPos(einfo.nixCode->errPos));
} else {
- out << fmt("%1%from command line argument", prefix) << std::endl;
- out << prefix << std::endl;
+ out << std::endl << fmt("%1%from command line argument", prefix);
}
+ nl = true;
}
// description
if (einfo.description != "") {
- out << prefix << einfo.description << std::endl;
- out << prefix << std::endl;
+ if (nl)
+ out << std::endl << prefix;
+ out << std::endl << prefix << einfo.description;
+ nl = true;
}
// lines of code.
if (einfo.nixCode.has_value() && einfo.nixCode->errLineOfCode.has_value()) {
+ if (nl)
+ out << std::endl << prefix;
printCodeLines(out, prefix, *einfo.nixCode);
- out << prefix << std::endl;
+ nl = true;
}
// hint
if (einfo.hint.has_value()) {
- out << prefix << *einfo.hint << std::endl;
- out << prefix << std::endl;
+ if (nl)
+ out << std::endl << prefix;
+ out << std::endl << prefix << *einfo.hint;
+ nl = true;
}
return out;