Commit graph

508 commits

Author SHA1 Message Date
Ben Burdette
4b5f9b35f0 env to bindings 2021-08-18 21:25:26 -06:00
Ben Burdette
2272021536 more error fixes 2021-08-18 20:02:23 -06:00
Ben Burdette
e82cf13b1e switch to fakeenvs 2021-08-18 17:53:10 -06:00
Ben Burdette
b6eb38016b moving towards env in exceptions 2021-08-17 14:39:50 -06:00
Ben Burdette
030271184f trying env args; but unecessary? 2021-08-09 14:30:47 -06:00
Ben Burdette
89264d20e6 move valmap to hh; add to env 2021-08-06 11:09:27 -06:00
Ben Burdette
129dd760e6 mapEnvBindings 2021-06-11 18:55:15 -06:00
Ben Burdette
d22de1dd0c remove dead code 2021-06-09 15:38:08 -06:00
Ben Burdette
93ca9381da formatting; string arg for throwTypeError 2021-06-08 18:37:28 -06:00
Ben Burdette
ebf530d31e line endings 2021-06-08 18:17:58 -06:00
Ben Burdette
ff2e72054f another throwTypeError form 2021-06-08 14:44:41 -06:00
Ben Burdette
99304334ca showType(fun) 2021-05-14 18:09:30 -06:00
Ben Burdette
644567cf7e clean up w LocalNoInline macro 2021-05-14 13:40:00 -06:00
Ben Burdette
17af7dc326 throwAssertionError, throwUndefinedError -> valmap-ized 2021-05-14 11:29:26 -06:00
Ben Burdette
d041dd874e throwEvalError form 4 2021-05-14 11:15:24 -06:00
Ben Burdette
ed74eaa07f throwEvalError form 3 2021-05-14 11:09:18 -06:00
Ben Burdette
989a4181a8 throwEvalError form 2 2021-05-14 11:06:20 -06:00
Ben Burdette
ab19d1685d throwEvalError; mapBindings 2021-05-13 16:00:48 -06:00
Ben Burdette
459bccc750 plain env pointer 2021-05-12 11:33:31 -06:00
Ben Burdette
0c2265da85 unique_ptr for valmap 2021-05-12 09:43:58 -06:00
Ben Burdette
e7847ad7a1 map1/2 for stack usage 2021-05-11 15:38:49 -06:00
Ben Burdette
a8fef9a6b1 throwTypeError with debugger/env 2021-05-10 18:36:57 -06:00
Ben Burdette
2dd61411af debugger on autoCallFunction error 2021-05-03 14:37:33 -06:00
Ben Burdette
57c2dd5d85 fixes 2021-04-28 09:55:08 -06:00
Ben Burdette
b466d51952 Merge branch 'master' into debugger-merge 2021-04-27 12:31:01 -06:00
Eelco Dolstra
293220bed5
Merge pull request #4440 from Ma27/misc-pos-fixes
Miscellaneous improvements for positioning in eval-errors
2021-04-23 11:10:59 +02:00
Maximilian Bosch
7c76964daa
libexpr: misc improvements for proper error position
When working on some more complex Nix code, there are sometimes rather
unhelpful or misleading error messages, especially if coerce-errors are
thrown.

This patch is a first steps towards improving that. I'm happy to file
more changes after that, but I'd like to gather some feedback first.

To summarize, this patch does the following things:

* Attrsets (a.k.a. `Bindings` in `libexpr`) now have a `Pos`. This is
  helpful e.g. to identify which attribute-set in `listToAttrs` is
  invalid.

* The `Value`-struct has a new method named `determinePos` which tries
  to guess the position of a value and falls back to a default if that's
  not possible.

  This can be used to provide better messages if a coercion fails.

* The new `determinePos`-API is used by `builtins.concatMap` now. With
  that change, Nix shows the exact position in the error where a wrong
  value was returned by the lambda.

  To make sure it's still obvious that `concatMap` is the problem,
  another stack-frame was added.

* The changes described above can be added to every other `primop`, but
  first I'd like to get some feedback about the overall approach.
2021-04-13 23:12:38 +02:00
Graham Christensen
d04969ffa5 EvalSettings::getDefaultNixPath: respect {restrict,pure}Eval
Otherwise Nix may look to invalid locations for channels.
2021-04-12 12:37:15 -04:00
Eelco Dolstra
665d4ec2da nix repl :doc: Don't return docs for partially applied primops
This gives misleading results for Nixpkgs functions like lib.toUpper.

Fixes #4596.
2021-03-03 17:52:57 +01:00
Eelco Dolstra
574eb2be81
Tweak error message 2021-02-22 15:24:14 +01:00
Eelco Dolstra
8d4268d190 Improve error formatting
Changes:

* The divider lines are gone. These were in practice a bit confusing,
  in particular with --show-trace or --keep-going, since then there
  were multiple lines, suggesting a start/end which wasn't the case.

* Instead, multi-line error messages are now indented to align with
  the prefix (e.g. "error: ").

* The 'description' field is gone since we weren't really using it.

* 'hint' is renamed to 'msg' since it really wasn't a hint.

* The error is now printed *before* the location info.

* The 'name' field is no longer printed since most of the time it
  wasn't very useful since it was just the name of the exception (like
  EvalError). Ideally in the future this would be a unique, easily
  googleable error ID (like rustc).

* "trace:" is now just "…". This assumes error contexts start with
  something like "while doing X".

Example before:

  error: --- AssertionError ---------------------------------------------------------------------------------------- nix
  at: (7:7) in file: /home/eelco/Dev/nixpkgs/pkgs/applications/misc/hello/default.nix

       6|
       7|   x = assert false; 1;
        |       ^
       8|

  assertion 'false' failed
  ----------------------------------------------------- show-trace -----------------------------------------------------
  trace: while evaluating the attribute 'x' of the derivation 'hello-2.10'
  at: (192:11) in file: /home/eelco/Dev/nixpkgs/pkgs/stdenv/generic/make-derivation.nix

     191|         // (lib.optionalAttrs (!(attrs ? name) && attrs ? pname && attrs ? version)) {
     192|           name = "${attrs.pname}-${attrs.version}";
        |           ^
     193|         } // (lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform && !dontAddHostSuffix && (attrs ? name || (attrs ? pname && attrs ? version)))) {

Example after:

  error: assertion 'false' failed

         at: (7:7) in file: /home/eelco/Dev/nixpkgs/pkgs/applications/misc/hello/default.nix

              6|
              7|   x = assert false; 1;
               |       ^
              8|

         … while evaluating the attribute 'x' of the derivation 'hello-2.10'

         at: (192:11) in file: /home/eelco/Dev/nixpkgs/pkgs/stdenv/generic/make-derivation.nix

            191|         // (lib.optionalAttrs (!(attrs ? name) && attrs ? pname && attrs ? version)) {
            192|           name = "${attrs.pname}-${attrs.version}";
               |           ^
            193|         } // (lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform && !dontAddHostSuffix && (attrs ? name || (attrs ? pname && attrs ? version)))) {
2021-01-21 11:02:09 +01:00
Domen Kožar
00f99fdfe6
Merge pull request #4240 from bburdette/2259-error-message
2259 error message - "auto-call" error
2021-01-15 18:26:21 +00:00
Eelco Dolstra
75efa42134 Move <nix/fetchurl.nix> into the nix binary
This makes the statically linked nix binary just work, without needing
any additional files.
2020-12-22 14:43:20 +01:00
Silvan Mosberger
b70d22baca
Replace Value type setters with mk* functions
Move clearValue inside Value

mkInt instead of setInt

mkBool instead of setBool

mkString instead of setString

mkPath instead of setPath

mkNull instead of setNull

mkAttrs instead of setAttrs

mkList instead of setList*

mkThunk instead of setThunk

mkApp instead of setApp

mkLambda instead of setLambda

mkBlackhole instead of setBlackhole

mkPrimOp instead of setPrimOp

mkPrimOpApp instead of setPrimOpApp

mkExternal instead of setExternal

mkFloat instead of setFloat

Add note that the static mk* function should be removed eventually
2020-12-18 21:48:22 +01:00
Silvan Mosberger
12e65078ef
Rename Value::normalType() -> Value::type() 2020-12-17 14:45:45 +01:00
Silvan Mosberger
d67e02919c
Rename ValueType -> InternalType, NormalType -> ValueType
And Value::type to Value::internalType, such that type() can be used in
the next commit to get the new ValueType
2020-12-17 14:45:22 +01:00
Silvan Mosberger
730b152b19
Make Value::type private
This is an implementation detail and shouldn't be used. Use normalType()
and the various is<Type> functions instead
2020-12-12 03:31:52 +01:00
Silvan Mosberger
bf98903967
Add ValueType checking functions for types that have the same NormalType 2020-12-12 03:31:50 +01:00
Silvan Mosberger
22ead43a0b
Use Value::normalType on all forced values instead of Value::type 2020-12-12 03:31:48 +01:00
Silvan Mosberger
9f056f7afd
Introduce Value type setters and make use of them 2020-12-12 03:31:48 +01:00
Silvan Mosberger
fa307875e9
Introduce NormalType for the normal type of a Value
This will be useful to abstract over the ValueType implementation
details

Make use of it already to replace the showType(ValueType) function
2020-12-12 03:31:46 +01:00
Christian Höppner
c4c3c15c19 Fix default nix-path
The default nix-path values for nixpkgs and root channels were
incorrect.
2020-11-12 15:46:08 +00:00
Ben Burdette
b327de9c2d change message 2020-11-11 11:09:59 -07:00
Ben Burdette
8895fa70a4 pare down the error message 2020-11-11 11:05:21 -07:00
Ben Burdette
3edfe6090e missing argument error 2020-11-11 09:29:32 -07:00
Ben Burdette
d8ef423a18 error message formatting 2020-11-09 19:16:50 -07:00
Ben Burdette
9f2b25ce55 remove unused ftn; reformat line breaks 2020-11-09 17:17:47 -07:00
Ben Burdette
6c2933a8d7 add position 2020-11-09 17:04:52 -07:00
Ben Burdette
107c91f5fe auto-call error 2020-11-09 16:48:35 -07:00
Eelco Dolstra
387f824cab
Merge pull request #4206 from hercules-ci/fix-coroutine-gc
Fix memory corruption caused by GC-invisible coroutine stacks
2020-11-05 10:18:31 +01:00