Do not exit from 'es -e' due to assignments#279
Merged
Conversation
When assignments were made to return values, this caused any shell running with the `-e' flag to exit whenever an assignment was performed. This makes the `-e' flag effectively unusable.
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.
When assignments were made to return values, this caused any shell running with the
-eflag to exit whenever an assignment was performed.While this isn't technically a bug in the sense of causing the shell to crash or violating the assumptions of an outside system, here's why I think it's obviously wrong:
It's inconsistent with every other shell, including rc. Es inherited the
-eflag from rc, but assignments in rc do not cause the shell to exit. Nor do they in bash, or zsh, or dash, or ksh, or tcsh.It's inconsistent with older versions of es: If you
git checkout v0.84and manage to get it to build, you'll find that assignments didn't cause the shell to exit back then. Yes, this is because back then they didn't produce a value, and now they do. However, in practical use assignments are thought of much less as value-producing commands and much more as, well, ways to modify variable values.It's unbelievably hard to use. A script that follows the current requirements of
-ecan only set values inside ofletorlocalbinders -- which is technically possible, but really unnecessarily tricky. For something that is effectively a convenience mechanism, this is a very strange way to be. Worse,It doesn't even work with built-in functions in initial.es. Both the
varsfunction and the%backgroundhook assign falsey values to variables (default flags and PIDs, respectively) on perfectly valid, successful calls, and have done so since (at least) 0.84. It is absurd to think that it was ever intended thatvarsand%backgroundshouldn't be callable from anes -escript.At a high level, it just doesn't make much sense. As wryun put it, "[t]he way I think about '-e' is that it's trying to catch results you've ignored, and if you've assigned the result you haven't ignored it". Supposedly,
-eis meant to be a "safety-by-default" convenience mechanism, but what possible safety is gained by disallowing assignments?es -eis pretty obviously not exercised much, given #180 and what it mentions aboutwhile-- as written in initial.es today, the body of awhileis run inside aniftest, so it doesn't getes -eprotection at all. So I think there is very little backwards compatibility to worry about.This is technically adding an exception to the semantics of
es -e, and the man page has had a couple sentence fragments added to account for that. However, it's a much more minor exception than the fact that the-ebehavior is turned off (dynamically) in the test of anif, which tends to cause surprising behavior when that test calls other functions (see #176). So this mechanism is hardly conceptually "clean" anyway -- why not at least make it halfway useful and culturally compatible?