Skip to content

Provide more context to OS errors #7695

Closed

Description

@melMass

Related problem

I believe it concerns a lot of OS errors, when failing they don't print out the path it tried to access.

Describe the solution you'd like

Return the path / variable value in errors where it makes sense

A few examples

They don't all make sense but illustrate the issue:

When using ^ on a variable:

image

When trying to touch, save or open an impossible path

Of course imagine this as part of a bigger pipeline/loop

> '\P:\x.txt'  | touch $in
# Failed to create file: The filename, directory name, or volume label syntax is incorrect. (os error 123)
> '\P:\x.txt' | save $in
# The filename, directory name, or volume label syntax is incorrect. (os error 123)
> '\P:\x.txt' | open $in
# The filename, directory name, or volume label syntax is incorrect. (os error 123)

I might add more if needed...

Activity

  1. added
    category:enhancement
    on Jan 6, 2023
  2. fdncred commented on Jan 6, 2023

    @fdncred
    Contributor

    I tracked this down to always being hard coded to false here

    command.run_with_input(engine_state, stack, input, false)

    It comes into play later when creating a label for the error.

    let label = match suggestion {
    Some(s) => {
    if reconfirm_command_name {
    format!(
    "'{}' was not found; did you mean '{s}'?",
    self.name.item
    )
    } else {
    let cmd_name = &self.name.item;
    let maybe_module = engine_state
    .which_module_has_decl(cmd_name.as_bytes(), &[]);
    if let Some(module_name) = maybe_module {
    let module_name = String::from_utf8_lossy(module_name);
    let new_name = &[module_name.as_ref(), cmd_name].join(" ");
    if engine_state
    .find_decl(new_name.as_bytes(), &[])
    .is_some()
    {
    format!("command '{cmd_name}' was not found but it was imported from module '{module_name}'; try using `{new_name}`")
    } else {
    format!("command '{cmd_name}' was not found but it exists in module '{module_name}'; try importing it with `use`")
    }
    } else {
    format!("did you mean '{s}'?")
    }
    }
    }
    None => {
    if reconfirm_command_name {
    format!("executable '{}' was not found", self.name.item)
    } else {
    "executable was not found".into()
    }
    }
    };
    Err(ShellError::ExternalCommand(
    label,
    err.to_string(),
    self.name.span,
    ))
    }
    // otherwise, a default error message
    _ => Err(ShellError::ExternalCommand(
    "can't run executable".into(),
    err.to_string(),
    self.name.span,
    )),
    }
    }

    I was able to hard code it to true and get an error message with a file name but if it's always true then @kubouch's new-ish code doesn't run. I think the synopsis is that we need a refactor around here.

  3. kubouch commented on Jan 6, 2023

    @kubouch
    Contributor

    Here is the PR that added the reconfirm_command_name #6730

  4. added
    A:error-unhelpful
    on Jan 12, 2023
  5. added a commit that references this issue on Jan 28, 2025
  6. added this to the v0.102.0 milestone on Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:error-unhelpfulcategory:enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions