From 59b94ee18ac0cba5c7b261ee72550a4d3db0acb5 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 5 Apr 2004 22:27:41 +0000 Subject: * When something goes wrong in the evaluation of a Nix expression, print a nice backtrace of the stack, rather than vomiting a gigantic (and useless) aterm on the screen. Example: error: while evaluating file `.../pkgs/system/test.nix': while evaluating attribute `subversion' at `.../pkgs/system/all-packages-generic.nix', line 533: while evaluating function at `.../pkgs/applications/version-management/subversion/default.nix', line 1: assertion failed at `.../pkgs/applications/version-management/subversion/default.nix', line 13 Since the Nix expression language is lazy, the trace may be misleading. The purpose is to provide a hint as to the location of the problem. --- src/libexpr/parser.y | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/libexpr/parser.y') diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index cfcbc589f61c..347516f69239 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -19,11 +19,20 @@ void setParseResult(void * data, ATerm t); void parseError(void * data, char * error, int line, int column); ATerm absParsedPath(void * data, ATerm t); ATerm fixAttrs(int recursive, ATermList as); +const char * getPath(void * data); void yyerror(YYLTYPE * loc, yyscan_t scanner, void * data, char * s) { parseError(data, s, loc->first_line, loc->first_column); } + +ATerm makePos(YYLTYPE * loc, void * data) +{ + return ATmake("Pos(, , )", + getPath(data), loc->first_line, loc->first_column); +} + +#define CUR_POS makePos(yylocp, data) %} @@ -55,15 +64,15 @@ expr: expr_function; expr_function : '{' formals '}' ':' expr_function - { $$ = ATmake("Function(, )", $2, $5); } + { $$ = ATmake("Function(, , )", $2, $5, CUR_POS); } | ID ':' expr_function - { $$ = ATmake("Function1(, )", $1, $3); } + { $$ = ATmake("Function1(, , )", $1, $3, CUR_POS); } | expr_assert ; expr_assert : ASSERT expr ';' expr_assert - { $$ = ATmake("Assert(, )", $2, $4); } + { $$ = ATmake("Assert(, , )", $2, $4, CUR_POS); } | expr_if ; @@ -123,9 +132,9 @@ binds bind : ID '=' expr ';' - { $$ = ATmake("Bind(, )", $1, $3); } + { $$ = ATmake("Bind(, , )", $1, $3, CUR_POS); } | INHERIT inheritsrc ids ';' - { $$ = ATmake("Inherit(, )", $2, $3); } + { $$ = ATmake("Inherit(, , )", $2, $3, CUR_POS); } ; inheritsrc -- cgit 1.4.1