Enable nushell error with backtrace#14945
Merged
WindSoilder merged 17 commits intonushell:mainfrom Feb 6, 2025
Merged
Conversation
Contributor
|
This is very cool! |
2a14591 to
4862a76
Compare
4862a76 to
681fec1
Compare
Contributor
|
I'm up for trying this when you are. |
Contributor
Author
|
Thanks! Let's land this. |
Contributor
|
I like this, but I don't think it's the solution for #13379. I'm guessing #13379 got auto-closed based on the mention above, but not sure. Custom-command authors who are writing a command for external consumption (e.g., |
WindSoilder
pushed a commit
that referenced
this pull request
Feb 20, 2025
# Description Resolves #15070 by removing the `BACKTRACE` message from all Nushell (non-panic) errors. This was added in #14945 and is useful for debugging, but not all that helpful to the typical shell user, especially since most shell errors won't have a backtrace anyway. At some point it would be nice to display this message only when there *is* a backtrace available. # User-Facing Changes Error messages will be more concise. # Tests + Formatting Updated tests. - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` # After Submitting We should include information in the *"Custom Commands"* chapter of the documentation on how to enable this for debugging.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
After this pr, nushell is able to raise errors with a backtrace, which should make users easier to debug. To enable the feature, users need to set env variable via
$env.NU_BACKTRACE = 1. But yeah it might not work perfectly, there are some corner cases which might not be handled.I think it should close #13379 in another way.
About the change
The implementation mostly contained with 2 parts:
introduce a new
ChainedErrorstruct as well as a newShellError::ChainedErrorvariant. Ifeval_instructionreturned an error, it converts the error toShellError::ChainedError.ChainedErrorstruct is responsable to display errors properly. It needs to handle the following 2 cases:error makeinternally, it needs to display the error itself along with caller span.error makedirectly, or some commands directly returns an error, we just want nushell raise an error abouterror make.Attach caller spans to
ListStreamandByteStream, because they are lazy streams, and only contains the span that runs it directly(like^false, for example), so nushell needs to add all caller spans to the stream.For example: in
def a [] { ^false }; def b [] { a; 33 }; b, when we runb, which runsa, which runs^false, theByteStreamonly contains the span of^false, we need to make it contains the span ofa, so nushell is able to get all spans if something bad happened.This behavior is happened after running
Instruction::Call, if it returns aByteStreamandListStream, it will callpush_caller_spanmethod to attach call spans.User-Facing Changes
It's better to demostrate how it works by examples, given the following definition:
Run
bdirectly shows the following error:Details
Run
b --list-streamshows the following errorDetails
Run
b --externalshows the following error:Details
It also added a message to guide the usage of NU_BACKTRACE, see the last line in the following example:
Tests + Formatting
Added some tests for the behavior.
After Submitting