-
Notifications
You must be signed in to change notification settings - Fork 27
Add "selectable exceptions" to $&catch
#216
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
base: master
Are you sure you want to change the base?
Conversation
With this change, the $&catch primitive is about as complex as a primitive should be. Arguably, 'retry' should be removed from the shell entirely, but this is a backwards-compatible half-measure, and it does demonstrate how to "reimplement" retry in case it is actually removed and people want to add it back.
This allows users to say `catch return @ value {echo $value} {command}`
and have that `catch` only catch return, and "pass through" anything
else.
|
This is good work! There is a regression in Restoring the original |
Also add a test case for signal blocking/unblocking in exception handlers.
That move adds a lot more complexity than it removes, so we'll just avoid changing $&catch for now and instead add selectable exceptions to fn-catch.
|
Well, that's disappointing, I was feeling good about having removed that nested I fixed it -- and added a test case that I think should prevent fools like me from breaking it again -- but now I'm not so sure that moving the For reasons I don't totally understand, I had to add a |
$&catch and add "selectable exceptions"$&catch
Understandable—i encountered the same issue when i was attempting to adapt Scheme's
Inside a catcher, signals are blocked, so when I can't quite understand why throwing |
I think this is exactly it, and I think I lean towards it being the most reasonable (that is, least surprising) behavior. Hypothetically, we could expose it to users better if we added blocked state to I've been thinking a little about how handling "all signals" is a thing that's hard to wrangle in es -- perhaps a |
|
Other than moving the (I can open a new discussion or issue to get ideas on how
The least surprising behavior for a shell, or any program, is the ability to interrupt execution at any time. On the other hand, the least surprising behavior for a signal handler is the inability for another signal to interrupt that signal handler.
It sounds easy enough to implement with
This bugs me as well. |
64361a8 to
a23a7a0
Compare
This PR:
Removes theretryexception from$&catch. This makes$&catchinto a quite minimal wrapper around theCatchExceptionmacro, which is probably how it should have been all along.Adds theretryexception back, viafn-catchin initial.es. This maintains backwards compatibility, though I'm personally sold on the idea of removingretryfrom es. It's spooky, hard-to-predict magic, and can lead to awful infinite loops if people don't defend against it in exception handlers. It's also (as proven in this PR) entirely possible to re-implement, for any users who are adamant about having it, or simulate in a simpler form where it's used.catchto only catch certain exceptions #165.With this PR, the following two are equivalent:
Note that when an exception is "selected", the first term isn't passed to the catcher. This is a little more magic than necessary, but it does make the code read very nice.
This version of "selectable exceptions" is fairly conservative; your only options are
catch foo @ {catcher} {body}orcatch @ {catcher} {body}. I think this is fine; it's simple in simple cases and the complicated version isn't actually all that complicated. If people want more sophisticated catch-like mechanisms, they can write them; the default shell shouldn't have much magic. (Admittedly, this is a more-than-minimal amount of magic, but in practical use, I think the "ROI" is good. Better thanretry, for sure.)As usual, there are alternatives to this PR, all of which I'm pretty open to. I'd love to rip out
retry, ever I saw since memreflect suggest it :)