forked from lix-project/lix
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.
This commit is contained in:
parent
40608342cb
commit
55849e153e
|
@ -43,9 +43,9 @@ string showErrPos(const ErrPos & errPos)
|
||||||
{
|
{
|
||||||
if (errPos.line > 0) {
|
if (errPos.line > 0) {
|
||||||
if (errPos.column > 0) {
|
if (errPos.column > 0) {
|
||||||
return fmt("(%1%:%2%)", errPos.line, errPos.column);
|
return fmt("%d:%d", errPos.line, errPos.column);
|
||||||
} else {
|
} else {
|
||||||
return fmt("(%1%)", errPos.line);
|
return fmt("%d", errPos.line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
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) {
|
switch (pos.origin) {
|
||||||
case foFile: {
|
case foFile: {
|
||||||
out << prefix << ANSI_BLUE << "at: " << ANSI_YELLOW << showErrPos(pos) <<
|
out << fmt(ANSI_BLUE "at " ANSI_YELLOW "%s:%s" ANSI_NORMAL ":", pos.file, showErrPos(pos));
|
||||||
ANSI_BLUE << " in file: " << ANSI_NORMAL << pos.file;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case foString: {
|
case foString: {
|
||||||
out << prefix << ANSI_BLUE << "at: " << ANSI_YELLOW << showErrPos(pos) <<
|
out << fmt(ANSI_BLUE "at " ANSI_YELLOW "«string»:%s" ANSI_NORMAL ":", showErrPos(pos));
|
||||||
ANSI_BLUE << " from string" << ANSI_NORMAL;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case foStdin: {
|
case foStdin: {
|
||||||
out << prefix << ANSI_BLUE << "at: " << ANSI_YELLOW << showErrPos(pos) <<
|
out << fmt(ANSI_BLUE "at " ANSI_YELLOW "«stdin»:%s" ANSI_NORMAL ":", showErrPos(pos));
|
||||||
ANSI_BLUE << " from stdin" << ANSI_NORMAL;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -272,7 +268,7 @@ std::ostream & showErrorInfo(std::ostream & out, const ErrorInfo & einfo, bool s
|
||||||
|
|
||||||
if (einfo.errPos.has_value() && *einfo.errPos) {
|
if (einfo.errPos.has_value() && *einfo.errPos) {
|
||||||
oss << "\n";
|
oss << "\n";
|
||||||
printAtPos("", *einfo.errPos, oss);
|
printAtPos(*einfo.errPos, oss);
|
||||||
|
|
||||||
auto loc = getCodeLines(*einfo.errPos);
|
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)) {
|
if (iter->pos.has_value() && (*iter->pos)) {
|
||||||
auto pos = iter->pos.value();
|
auto pos = iter->pos.value();
|
||||||
oss << "\n";
|
oss << "\n";
|
||||||
printAtPos("", pos, oss);
|
printAtPos(pos, oss);
|
||||||
|
|
||||||
auto loc = getCodeLines(pos);
|
auto loc = getCodeLines(pos);
|
||||||
if (loc.has_value()) {
|
if (loc.has_value()) {
|
||||||
|
|
|
@ -17,10 +17,10 @@ nix-env -q --foo 2>&1 | grep "unknown flag"
|
||||||
|
|
||||||
# Eval Errors.
|
# Eval Errors.
|
||||||
eval_arg_res=$(nix-instantiate --eval -E 'let a = {} // a; in a.foo' 2>&1 || true)
|
eval_arg_res=$(nix-instantiate --eval -E 'let a = {} // a; in a.foo' 2>&1 || true)
|
||||||
echo $eval_arg_res | grep "at: (1:15) from string"
|
echo $eval_arg_res | grep "at «string»:1:15:"
|
||||||
echo $eval_arg_res | grep "infinite recursion encountered"
|
echo $eval_arg_res | grep "infinite recursion encountered"
|
||||||
|
|
||||||
eval_stdin_res=$(echo 'let a = {} // a; in a.foo' | nix-instantiate --eval -E - 2>&1 || true)
|
eval_stdin_res=$(echo 'let a = {} // a; in a.foo' | nix-instantiate --eval -E - 2>&1 || true)
|
||||||
echo $eval_stdin_res | grep "at: (1:15) from stdin"
|
echo $eval_stdin_res | grep "at «stdin»:1:15:"
|
||||||
echo $eval_stdin_res | grep "infinite recursion encountered"
|
echo $eval_stdin_res | grep "infinite recursion encountered"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue