Let's collect some questions a lot of Nushell contributors have.
- How do I do....?
- Why do I need to do certain things a certain way?
Let's keep the answers concise and up to date (or general enough) to remain relevant
TODO (Probably fork out into its own file)
Approximate flow:
- Are you reporting the error in the parser/static checking phase?
- Use
nu_protocol::ParseErrorvariants - Follow the logic used in the context as we need to collect multiple errors for a good IDE experience
- Use
- Pick the right
nu_protocol::ShellErrorvariant- Does a matching existing variant fit your need? (go to references of the
ShellErrorvariant for inspiration) - Check what context the
miettemacros add during formatting! (go to definition ofShellError) - If it is a one-of specific error, consider using a generic variant
- Else add a new class of errors
- add the necessary
Spaninformation - general shared error text, to inform and point to a resolution
- dynamic information gathered from the error site
- Don't use a tuple enum variant, named structs going forward only!
- add the necessary
- Does a matching existing variant fit your need? (go to references of the
- Are you in a command?
return Err(ShellError::...)and you're done in aCommand::run
- Do you want to report a warning but not stop execution?
- NEVER
println!, we can write to stderr if necessary but... - good practice:
nu_protocol::report_error::report_errororreport_error_new- depending on whether you have access to a
StateWorkingSet
- depending on whether you have access to a
- if only relevant to in the field debugging:
log-crate macros.
- NEVER
TODO
TODO