[Nix-dev] Usefulness of adderrorContext

Eelco Dolstra e.dolstra at tudelft.nl
Fri Nov 20 16:11:07 CET 2009


Marc Weber wrote:
> Run this example and you'll  get:
> 
> == result
> /tmp/test-nix-add-error-context.nix|1 col 4| error: while evaluating the attribute `<let-body>'
> /tmp/test-nix-add-error-context.nix|8 col 8| while evaluating the function
> /tmp/test-nix-add-error-context.nix|10 col 7| while evaluating the attribute `take'
> /tmp/test-nix-add-error-context.nix|5 col 9| while evaluating the attribute `name'
> || value
> || value is an integer while an attribute set was expected
> == code
> 
> let 
>   inherit (builtins) addErrorContext;
> 
>   attr = addErrorContext "attr" {
>     name = addErrorContext "value" (2).abc;
>   };
> 
>   f = x: x;
> 
>   take = attr.name;
> 
> in f take
> 
> So what happened to the error context "attr" ?

This is correct behaviour.  `addErrorContext' merely adds a message to the
backtrace during the evaluation of `attr', and since `attr' immediately succeeds
and returns an attribute set, you never get to see the message.

-- 
Eelco Dolstra | http://www.st.ewi.tudelft.nl/~dolstra/



More information about the nix-dev mailing list