-
Notifications
You must be signed in to change notification settings - Fork 2.1k
error make ability to reference caller span #13379
Copy link
Copy link
Open
Labels
A:error-handlingHow errors in externals/nu code are caught or handled programmatically (see also unhelpful-error)How errors in externals/nu code are caught or handled programmatically (see also unhelpful-error)category:enhancementNew feature or requestNew feature or request
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A:error-handlingHow errors in externals/nu code are caught or handled programmatically (see also unhelpful-error)How errors in externals/nu code are caught or handled programmatically (see also unhelpful-error)category:enhancementNew feature or requestNew feature or request