Add "selectable exceptions" to $&catch#216
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
|
Coming back to this, I changed my mind and moved the selectable exception logic directly into |
This PR adds the "selectable exceptions" behavior proposed in #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 :)