nix icon indicating copy to clipboard operation
nix copied to clipboard

builtins.readDir: fix nix error trace on filesystem errors

Open Mic92 opened this issue 1 year ago • 8 comments

Motivation

builtins.readDir: fix nix error trace on filesystem errors

Before:

nix-env % ./src/nix/nix eval --impure --expr 'let f = builtins.readDir "/nix/store/39z5zpb72qrnxl832nwphcd4ihfhix3j-hello-2.12.1/foobar"; in f' --show-trace                                           
error: filesystem error: directory iterator cannot open directory: No such file or directory [/nix/store/39z5zpb72qrnxl832nwphcd4ihfhix3j-hello-2.12.1/foobar]                                         

After:

error:                                                                                                                                                                                                 
       … while calling the 'readDir' builtin                                                                                                                                                           
         at «string»:1:9:                                                                                                                                                                              
            1| let f = builtins.readDir "/nix/store/39z5zpb72qrnxl832nwphcd4ihfhix3j-hello-2.12.1/foobar"; in f                                                                                        
             |         ^                                                                                                                                                                               
                                                                                                                                                                                                       
       error: reading directory content failed: filesystem error: directory iterator cannot open directory: No such file or directory [/nix/store/39z5zpb72qrnxl832nwphcd4ihfhix3j-hello-2.12.1/foobar]

Context

Priorities and Process

Add :+1: to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

Mic92 avatar Aug 26 '24 19:08 Mic92

There are sure more errors like this in here. I see for example a few "fs::is_$type", which can also throw errors.

Mic92 avatar Aug 26 '24 19:08 Mic92

Now that @Ericson2314 is mentioning it the SysError one might actually not be the right one to use for rethrowing

Mic92 avatar Aug 26 '24 20:08 Mic92

This is now mergeable.

Mic92 avatar Aug 27 '24 05:08 Mic92

I would convert to a nix exception in PosixSourceAccessor::readDirectory, and then make the catch-rethrow in the evaluator just add the position info.

We want all SourceAccessors to throw the same sorts of exceptions, I think.

Ericson2314 avatar Aug 27 '24 14:08 Ericson2314

@mergifyio rebase

roberth avatar Aug 28 '24 12:08 roberth

rebase

❌ Unable to rebase: user roberth is unknown.

Please make sure roberth has logged in Mergify dashboard.

mergify[bot] avatar Aug 28 '24 12:08 mergify[bot]

@mergify rebase

roberth avatar Aug 28 '24 12:08 roberth

rebase

✅ Branch has been successfully rebased

mergify[bot] avatar Aug 28 '24 12:08 mergify[bot]

@Ericson2314 ok. This is better. I also fixed a similar issue in :lf, which would make the repl crash.

Mic92 avatar Sep 05 '24 09:09 Mic92

Fixed following the suggestions of @Ericson2314 and also fixed a similar repl crash.

Mic92 avatar Sep 05 '24 09:09 Mic92

@Ericson2314 applied

Mic92 avatar Sep 10 '24 21:09 Mic92

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nix-2-25-released/55994/1

nixos-discourse avatar Nov 13 '24 14:11 nixos-discourse