* Don't show trace information by default (`--show-trace' to enable).
NixOS evaluation errors in particular look intimidating and generally aren't very useful. Ideally the builtins.throw messages should be self-contained.
This commit is contained in:
parent
a2fc3a53ba
commit
f2c3fc5191
6 changed files with 21 additions and 3 deletions
|
@ -24,6 +24,7 @@
|
||||||
<arg><option>--fallback</option></arg>
|
<arg><option>--fallback</option></arg>
|
||||||
<arg><option>--readonly-mode</option></arg>
|
<arg><option>--readonly-mode</option></arg>
|
||||||
<arg><option>--log-type</option> <replaceable>type</replaceable></arg>
|
<arg><option>--log-type</option> <replaceable>type</replaceable></arg>
|
||||||
|
<arg><option>--show-trace</option></arg>
|
||||||
<sbr />
|
<sbr />
|
||||||
|
|
||||||
</nop>
|
</nop>
|
||||||
|
|
|
@ -305,6 +305,14 @@
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><option>--show-trace</option></term>
|
||||||
|
|
||||||
|
<listitem><para>Causes Nix to print out a stack trace in case of Nix
|
||||||
|
expression evaluation errors.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
</variablelist>
|
</variablelist>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,7 @@ static Expr prim_abort(EvalState & state, const ATermVector & args)
|
||||||
static Expr prim_throw(EvalState & state, const ATermVector & args)
|
static Expr prim_throw(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
PathSet context;
|
PathSet context;
|
||||||
throw ThrownError(format("user-thrown exception: `%1%'") %
|
throw ThrownError(format("user-thrown exception: %1%") %
|
||||||
evalString(state, args[0], context));
|
evalString(state, args[0], context));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,6 +125,9 @@ RemoveTempRoots::~RemoveTempRoots()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool showTrace = false;
|
||||||
|
|
||||||
|
|
||||||
/* Initialize and reorder arguments, then call the actual argument
|
/* Initialize and reorder arguments, then call the actual argument
|
||||||
processor. */
|
processor. */
|
||||||
static void initAndRun(int argc, char * * argv)
|
static void initAndRun(int argc, char * * argv)
|
||||||
|
@ -243,6 +246,8 @@ static void initAndRun(int argc, char * * argv)
|
||||||
maxSilentTime = getIntArg(arg, i, args.end());
|
maxSilentTime = getIntArg(arg, i, args.end());
|
||||||
else if (arg == "--no-build-hook")
|
else if (arg == "--no-build-hook")
|
||||||
useBuildHook = false;
|
useBuildHook = false;
|
||||||
|
else if (arg == "--show-trace")
|
||||||
|
showTrace = true;
|
||||||
else if (arg == "--option") {
|
else if (arg == "--option") {
|
||||||
++i; if (i == args.end()) throw UsageError("`--option' requires two arguments");
|
++i; if (i == args.end()) throw UsageError("`--option' requires two arguments");
|
||||||
string name = *i;
|
string name = *i;
|
||||||
|
@ -365,7 +370,9 @@ int main(int argc, char * * argv)
|
||||||
% e.what() % programId);
|
% e.what() % programId);
|
||||||
return 1;
|
return 1;
|
||||||
} catch (BaseError & e) {
|
} catch (BaseError & e) {
|
||||||
printMsg(lvlError, format("error: %1%") % e.msg());
|
printMsg(lvlError, format("error: %1%%2%") % (showTrace ? e.prefix() : "") % e.msg());
|
||||||
|
if (e.prefix() != "" && !showTrace)
|
||||||
|
printMsg(lvlError, "(use `--show-trace' to show detailed location information)");
|
||||||
return 1;
|
return 1;
|
||||||
} catch (std::exception & e) {
|
} catch (std::exception & e) {
|
||||||
printMsg(lvlError, format("error: %1%") % e.what());
|
printMsg(lvlError, format("error: %1%") % e.what());
|
||||||
|
|
|
@ -24,12 +24,14 @@ using boost::format;
|
||||||
class BaseError : public std::exception
|
class BaseError : public std::exception
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
string prefix_; // used for location traces etc.
|
||||||
string err;
|
string err;
|
||||||
public:
|
public:
|
||||||
BaseError(const format & f);
|
BaseError(const format & f);
|
||||||
~BaseError() throw () { };
|
~BaseError() throw () { };
|
||||||
const char * what() const throw () { return err.c_str(); }
|
const char * what() const throw () { return err.c_str(); }
|
||||||
const string & msg() const throw () { return err; }
|
const string & msg() const throw () { return err; }
|
||||||
|
const string & prefix() const throw () { return prefix_; }
|
||||||
BaseError & addPrefix(const format & f);
|
BaseError & addPrefix(const format & f);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ BaseError::BaseError(const format & f)
|
||||||
|
|
||||||
BaseError & BaseError::addPrefix(const format & f)
|
BaseError & BaseError::addPrefix(const format & f)
|
||||||
{
|
{
|
||||||
err = f.str() + err;
|
prefix_ = f.str() + prefix_;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue