-
-
Notifications
You must be signed in to change notification settings - Fork 307
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
Allow inspecting cause of exceptions #208
Comments
Related – perhaps it should have been a separate issue, but here goes: I'd like to be able to re-throw an exception after capturing it, either via the Suggestion:
|
This also explicitly documents `float64` as a data type, although that is a byproduct of this change. I created this change because someone asked on the project's Gitter channel how to extract useful info from an exception object. Related elves#208
This also explicitly documents `float64` as a data type, although that is a byproduct of this change. I created this change because someone asked on the project's Gitter channel how to extract useful info from an exception object. Related elves#208
This also explicitly documents `float64` as a data type, although that is a byproduct of this change. I created this change because someone asked on the project's Gitter channel how to extract useful info from an exception object. Related elves#208
This documents all numeric literal forms. As of Go 0.13 octal and binary numeric literals are supported. Which means that Elvish supports such literals. Since Go 0.13 is now the minimum Go version document those numeric literals. It also adds a related section that documents the existence of an exception data type but punts a detailed description to an existing section on how exceptions work. Fixes elves#614 Related elves#208 Address PR review feedback
This documents all numeric literal forms. As of Go 0.13 octal and binary numeric literals are supported. Which means that Elvish supports such literals. Since Go 0.13 is now the minimum Go version document those numeric literals. It also adds a related section that documents the existence of an exception data type but punts a detailed description to an existing section on how exceptions work. Fixes elves#614 Related elves#208 Address PR review feedback
This documents all numeric literal forms. As of Go 0.13 octal and binary numeric literals are supported. Which means that Elvish supports such literals. Since Go 0.13 is now the minimum Go version document those numeric literals. It also adds a related section that documents the existence of an exception data type but punts a detailed description to an existing section on how exceptions work. Fixes #614 Related #208 Address PR review feedback
A comprehensive design is not there yet, but at least it should also be possible to access the message inside an exception raised by |
Exposing the traceback is a bit hairy, so for the sake of this issue I'll focus on just the cause. Exposing the traceback is tracked in #1042. |
Design notes:
There is an open question regarding how to expose the many methods of Go's
|
I think |
After researching a bit more on how to name this: "exit" and "exit code" actually have narrower meanings than I thought (at least on the POSIX C API level). A process exits only when it terminates on its own. If it was killed by a signal, it never exited, and there is no exit code, only a signal number. POSIX uses 128+N to signal a command was killed by a signal; Elvish could distinguish the two different cases by giving them different predicates (that seems to be what @hanche is suggesting). I'd pick different names though; |
Note that is a POSIX shell (mis)feature. It is not a feature of the underlying kernel API. In UNIX the exit status is in the range [0, 255]. Exiting due to a signal is encoded in a fashion that ensures there is no ambiguity between SIGHUP (signal #1) and the program calling |
|
These predicates are for exceptions, not errors. Moreover, Elvish doesn't really have a concept of errors, only exceptions. This addresses #208.
Also, see this statement from https://en.wikipedia.org/wiki/Exit_status:
The POSIX 1003.2 shell standard more or less says the same thing. However, both documents are ambiguous. I find this situation particularly hilarious given how many fans of the ksh shell assert that it is 100% POSIX compliant. Ksh complies with the POSIX convention regarding the special exit statuses "126" and "127" but not the POSIX mandate to confuse an exit status in the range [128..255] with a termination due to a signal. At least with respect to the magic The bottom line is that it is impossible for Elvish to do the right thing, all of the time, with respect to exit statuses. One option is to follow the path I established for the Meson build system. See mesonbuild/meson@5290f41. However, I recommend that Elvish not attempt to handle shells that munge the exit status of the last external command they run. Just map the native API to an Elvish exception object. Don't attempt to divine (i.e., discover by guesswork) a) if the external command really exited due to a signal as reported by the OS, or b) exited by a signal because the external command was a shell that munged the exit status of the external command it ran. |
It would be good sometimes to be able to query the exit code of the last command executed, without the need to capture an exception for it. My specific current use case is the implementation of iTerm2's Shell Integration features for Elvish, which among other things allow displaying a prompt marker which can indicate via its color the status of the last command. My current implementation is at https://github.com/zzamboni/elvish-modules/blob/master/iterm2.org, which works, but the marker is always displayed with the same color because there is no way to obtain this information. I'm sure other use cases can be identified. Maybe something like |
@zzamboni for that use case, I'd introduce an API for a default exception handler that is run interactively. |
Errors are now opaque values. One should be able to inspect them by indexing into relevant fields. For instance, the following may be used to retrieve the exit code of an external command:
The text was updated successfully, but these errors were encountered: