Skip to content

file_not_found/directory_not_found on evaluated string doesn't say what the path is; makes error hard to debug #10406

@carols10cents

Description

@carols10cents

Describe the bug

Hi, I'm nu new, so I'm writing a bunch of stuff that doesn't work yet 😅 I have a script that is using string interpolation to build a list of paths, and then is trying to open each path.

When I run my script, I'm getting a "directory not found" error pointing at my string interpolated value, but it doesn't tell me the evaluated value that causes the error, so it's hard for me to know what the problem is.

Here's my script:

def main [rust_project_dir: path] {
    open $"($rust_project_dir)/Cargo.toml" | get workspace.members | each { |crate|
        open $"($rust_project_dir)($crate)/src/lib.rs"
    }
}

I'm running it as nu script.nu /path/to/my/rust/workspace, and I'm getting this error:

Error: nu::shell::eval_block_with_input

  × Eval block failed with pipeline input
   ╭─[/Users/carolnichols/Nu/workspace-lints/script.nu:1:1]
 1 │ def main [rust_project_dir: path] {
 2 │     open $"($rust_project_dir)/Cargo.toml" | get workspace.members | each { |crate|
   ·     ──┬─
   ·       ╰── source value
 3 │         open $"($rust_project_dir)($crate)/src/lib.rs"
   ╰────

Error: nu::shell::directory_not_found

  × Directory not found
   ╭─[/Users/carolnichols/Nu/workspace-lints/script.nu:2:1]
 2 │     open $"($rust_project_dir)/Cargo.toml" | get workspace.members | each { |crate|
 3 │         open $"($rust_project_dir)($crate)/src/lib.rs"
   ·              ────────────────────┬────────────────────
   ·                                  ╰── directory not found
 4 │     }
   ╰────

How to reproduce

  1. Write a nu script with a loop that uses string interpolation to build filenames and then open each file.
  2. Remove one or more of the files that the script expects should exist.
  3. Run the script and observe that the error message doesn't say what the actual, evaluated value is that caused the problem.
  4. Imagine not knowing which file was removed and despair :)

Expected behavior

I expected the error message in my particular case to say something like directory "/Users/carolnichols/rust/my-workspace/foo/src/lib.rs" not found; somewhere showing the actual value passed to open that caused the problem.

Screenshots

No response

Configuration

key value
version 0.84.0
branch
commit_hash
build_os macos-aarch64
build_target aarch64-apple-darwin
rust_version rustc 1.71.1 (eb26296b5 2023-08-03) (built from a source tarball)
cargo_version cargo 1.71.2 (1a737af0c 2023-08-07)
build_time 2023-08-22 21:09:23 +00:00
build_rust_channel release
allocator standard
features dataframe, default, sqlite, trash, which, zip
installed_plugins

Additional context

I think I'm also hitting #10085 as I think this error should be "file not found" rather than "directory not found". I didn't find an issue that was exactly what I'm reporting here when I looked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:error-unhelpfulThe error message you observe is not helpful to identify the problemcategory:enhancementNew feature or requestdeprecated:questionQuestions should be redirected to GitHub discussionsusage:script-fileIssues related to executing a script file (as opposed to a module or sourcing)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions