-
-
Notifications
You must be signed in to change notification settings - Fork 94
Move bash 3 version check to top of file for early exit #114
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
Conversation
This test fails with:
/app/cli: line 117: conditional binary operator expected
/app/cli: line 117: syntax error near `missingno'
/app/cli: line 117: ` if [[ -v missingno ]]; then'
Bash executes the script as it's reading it. When it encounters a function, it parses the function body before continuing. The bashly-generated script has *all* of its code in functions which appear before any code is executed (the initialize/run functions are only called at the bottom of the script). Normally this is useful, since it ensures that bash has loaded/parsed the whole script before beginning execution; however, in the case of this version check it means that if any of the functions contain syntax that Bash 3 doesn't understand, it will choke on that and crash (with a much less helpful error) before it has a chance to execute the version check. This commit moves that check to the very top of the file, where it will be executed and trigger an early exit before bash tries to parse the rest of the script, so that it will work correctly regardless of the remainder of the contents.
|
I am still reluctant to add something (that exits, no less) outside of any function. Could you provide the simplest bashly config + code for, say, Also see #113 (comment) - perhaps providing user hooks in some places for the developer to inject code could solve all these problems without introducing strict and dangerous limitations. Bash 3 is really something I have no plans on spending a lot of time on - it is borderline archaic, and would be like spending time on IE 11 today. The friendly bounce warning was just a courtesy - if it serves any purpose, good, if it can be slightly improved without introducing side effects or complexity, also good - otherwise, it should simply be removed and replaced with places for users to inject whatever they need. |
|
Yes, if you check out only the first commit of the series you will find a failing test. (Though I made it a |
no need to rearrange - just a reference. You mean these yes? bf3955a#diff-89b4c3fdacc5cec5f8b9a9fd5ee665c0640b1e1966574f32a7422862b592ec6f bf3955a#diff-9abd7c2657991bbfacd6f44065713e70d12327fc17d97b412f7658cbfb0db2a5 |
|
Well. I am able to reproduce the issue clear as day. Did you consider the |
|
I did think briefly about the wrap feature, though maybe there's a use-case for it I'm not considering. My thoughts were:
(Edit: I was thinking about the Bash 3 case all wrong, though the result still stands) |
|
Yeah. Well, my current position is this: I realize you have put a lot of thought and effort into this, and I appreciate it. My reasoning:
Your thoughts? (and for future reference, to avoid work that may not be merged, perhaps lets open new ideas in an issue before PR). |
... as is the case with any software, you need to know how to use it. This can be a
See my other comment. I am not convinced at all. This has the potential to cause unwanted side effects as I see it, than good. |
|
My thoughts on your reasoning, as requested:
I wish!
This is true, though less inscrutable error messages are still helpful if their friend or colleague is using a Mac.
This is true, but the out-of-the-box scripts also don’t actually do anything. It would be nice if, when you actually use bashly, the check that it ostensibly provides didn't break because of a seemingly innocent implementation. On a much more general note, a quick summary of where we stand:
My philosophy is that error handling and correctness checks should be pushed as far upstream as possible, to make it easier for more people to benefit from them; but since the hooks will provide a workaround that fits my needs I’m OK with dropping my two open PRs and using hooks instead. Yours is also a reasonable stance, just a different one; and as it's not my project I leave it up to you to make the final decision on which direction to go in. TLDR: Feel free to close #113 and #114 if you don't like them; I’d like to see Bashly have better support for these situations but am OK with keeping my opinions confined to my own scripts.
(This is a tricky balancing act. In the case of these two PRs, most of what we’ve been discussing has come up as a result of having code to look at and wouldn't necessarily have been obvious before I started implementing. This is why I submitted #114 as a draft needing cleanup, once I realized that it wasn’t as simple as I had anticipated and would need discussion before merging.) |
I wouldn't say that the ~500 lines of code that are generated by
Interesting point - I didn't consider that.
This is my philosophy as well. The only difference between us is that I have two philosophies that take precedence:
Me too, but not at any cost. For me - this is the important question: Is there a way to make bashly compatible with If the answer is yes, then the solution is obvious:
|
|
And BTW - I may still decide to merge this. Perhaps after some sleep I will look at it differently. |
Yes, exactly—mainly because of
I think this could be fixed by changing that expression to |
|
I have reviewed all changes, looks good. Now only left to decide if we want this or not. It is now somewhat easier to accept, since there is an ability for the user to replace it with a custom header. It is the same reason that renders it a little less necessary though. Just a matter of what we feel is a better default, and I know your stand on the subject is that this is a better default. If we merge it, I will also probably want to change the header for when generating with For now, lets keep it open until I decide one way or another, or until more evidence comes to light to tip the scale. |
Bash executes the script as it's reading it. When it encounters a function, it parses the function body before continuing. The bashly-generated script has all of its code in functions which appear before any code is executed (the initialize/run functions are only called at the bottom of the script). Normally this is useful, since it ensures that bash has loaded/parsed the whole script before beginning execution; however, in the case of this version check it means that if any of the functions contain syntax that Bash 3 doesn't understand, it will choke on that and crash (with a much less helpful error) before it has a chance to execute the version check:
This PR adds a test for this situation and moves that check to the very top of the file, where it will be executed and trigger an early exit before bash tries to parse the rest of the script, so that it will work correctly regardless of the remainder of the contents.
(Extracted from #113 for clarity.)