Skip to content

error make ability to reference caller span #13379

@NotTheDr01ds

Description

@NotTheDr01ds

Related problem

When throwing an error via error make in a custom command, the default span points to the error make. It would be much more user-friendly (and useful) if there was some way to point it to the command itself.

Example:

def problem [] {
  let error_condition = true
  if $error_condition {
    error make {
      msg: "Oops"
    }
  }
}
> problem
Error:   × Oops
   ╭─[entry #14:4:5]
 3 │   if $error_condition {
 4 │     error make {
   ·     ─────┬────
   ·          ╰── originates from here
 5 │       msg: "Oops"
   ╰────

Describe the solution you'd like

Some way in the error make to specify that the span should be the calling custom command. Preferably also some way to point to its input or arguments as the culprit.

E.g.:

def problem [] {
  let error_condition = true
  if $error_condition {
    error make {
      msg: "Oops"
      source: "caller" # and/or perhaps "pipeline" or "arguments"
    }
  }
}

Describe alternatives you've considered

I can obtain the entire caller via view files | last, but this isn't helpful if the previous "file" called the command multiple times.

Additional context and details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:error-handlingHow errors in externals/nu code are caught or handled programmatically (see also unhelpful-error)category:enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions