Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a chapter about errors #772

Open
Hofer-Julian opened this issue Feb 8, 2023 · 5 comments
Open

Add a chapter about errors #772

Hofer-Julian opened this issue Feb 8, 2023 · 5 comments

Comments

@Hofer-Julian
Copy link
Contributor

Hofer-Julian commented Feb 8, 2023

One concept that I still find quite hard to grasp are Nushell's errors.
As far as I can tell, they behave like raised exceptions in a language like Python.
They bubble up, but can be caught with try or do -i.
However, I haven't seen that spelled out yet.

I see that nushell errors are also created if external commands exit with a non-zero exit code.
But also that isn't mentioned in the book.

I would be happy to add a chapter about errors in Nushell if someone could me guide through the things I am unsure about.

Topics to cover:

  • behavior of errors
  • try
  • do
  • error make
  • complete
@fdncred
Copy link
Collaborator

fdncred commented Feb 8, 2023

I think this would be a great add. You may want to mention error make and complete as well. It may also be helpful to know that do has undergone some changes recently. So, I'd love some thorough documentation on it. I really don't understand why now you can just use do without the i sometimes.

@Hofer-Julian
Copy link
Contributor Author

You may want to mention error make and complete as well

Good point, added it to a list of topics to cover

It may also be helpful to know that do has undergone some changes recently. So, I'd love some thorough documentation on it. I really don't understand why now you can just use do without the i sometimes.

Not sure what you mean there, at the moment, do takes a closure and can optionally accept command line flags according to the docs.

Regarding exceptions.
Is there any relevant difference to exceptions in other languages which should be pointed out?

@fdncred
Copy link
Collaborator

fdncred commented Feb 8, 2023

Not sure what you mean there, at the moment,

There used to be a difference between these two commands (not in a directory with a git repo). Now there doesn't appear to be.

do -i { git branch --show-current }

and

do { git branch --show-current }

and with capturing the output.

do -i { git branch --show-current } | complete

and

do { git branch --show-current } | complete

@Hofer-Julian
Copy link
Contributor Author

Hofer-Julian commented Feb 8, 2023

@fdncred I can see the following difference

# test1.nu
do { git branch --show-current }
echo Hello
$ nu test1.nu
fatal: not a git repository (or any of the parent directories): .git
# test2.nu
do -i { git branch --show-current }
echo Hello
$ test2.nu
fatal: not a git repository (or any of the parent directories): .git
Hello

@fdncred
Copy link
Collaborator

fdncred commented Feb 8, 2023

That's great that you've found a difference. Whatever all the differences are in those do commands should be documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants