-
- Notifications
You must be signed in to change notification settings - Fork 94
Make bashly-generated code set -u-safe #113
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 will be needed later, since we'll be using syntax that this version can no longer even parse so we need to early exit before it has a chance to see that.
Otherwise we can end up accidentally testing an *older* version of the templates, which is a very confusing experience (especially since this file is regenerated by some later tests, so the problem will mysteriously disappear on the next run).
| printf "<%= strings[:unsupported_bash_version] -%>\n" | ||
| exit 1 | ||
| fi | ||
| set -eu -o pipefail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DANGER DANGER: This will obviously break a lot of scripts if merged in. I stuck this here for testing but I'm not sure what the best way to handle this is. Maybe just adding this to every example's initialize.sh?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can generate this line conditionally, for example, if the environment variable BASHLY_STRICT is set. And then ENV['BASHLY_STRICT'] = '1' can be added to the spec helper.
This has the positive side effect of letting users generate strict scripts as well by just setting this variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to put this as a flag like bashly generate --strict rather than an env var?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally, I suggested an env var, since I did not intend this to be a user-facing feature. Only enabled when the tests execute. If users want to add something, they have the initialize.sh for this - no need for new flags I think.
| I am not so sure about the necessity of this. If users want it in their script, they can add it to the initialization sequence, and for bashly itself, I am not sure it is required. Have you seen a bug that this would have helped catch? |
This is the trouble. If you do that the generated script will crash because it runs I do agree that this shouldn't be forced on users, hence my comment on
You mean to catch bugs in bashly? I agree, I don't think this is very important for checking bashly itself, but it is important to have so that user scripts can have this option set without having to turn it off before calling into bashly-generated code.
Yes, this PR was prompted by me writing a bug that accidentally deleted a file because I made a mistake when writing the argument name. I then went to add On a side note, I find it interesting that bashly sets |
| Ok, I see your point now. You wish to make the generated scripts "set -u compliant", and not add "set -u" as a default. With this I can agree. Just need to have a PR clean of anything that is debatable.
Setting |
| BTW - I was thinking that perhaps another way to tackle this problem it to add an optional This will have this logical order:
|
| By the way, I am still OK with continuing with this PR - if it only contains changes that make bashly If you want to clean it up, and mark it ready for review, I will merge (or if my help or attention is needed, please point me where I am needed). |
| Putting this PR on hold pending discusison on #114 (comment) |
| As I see it now (after the recent merged PRs), this PR can become valid under these assumptions:
Then, users who wish to include code that breaks parsing in bash 3, must implement a custom header. If this is not possible, or complex - I suggest closing this PR. In this case, users can add |
| That sounds like a reasonable approach; I'll try to make some time soon to clean up this PR to fix bash 3 support. Also, continuing this discussion:
I don't have a strong opinion either way, I just feel like this may be an inconsistency. |
Well - bashly is just a tad opinionated. Also, don't forget that bash was designed to allow these unset vars - as can be seen in this very PR - natural ways of writing things in bash, fail with this enabled. |
| Per your note on #121 (comment), LMK what you decide about this PR. Happy to make it Bash 3-compatible as we discussed. |
Well - if you are still up for it, and the resulting PR does not complicate things too much, and my points in this comment are met (assuming you agree they are valid) - sure, why not. Happy to get this merged as well. As for the short discussion around DANGER DANGER - I would like to implement it myself, after you finish your touches. You just add the necessary |
| @wolfgang42 - you were nowhere to be found for some of our other PRs. Is this one still happening? |
| @wolfgang42 - I see you are no longer available to continue this, and since the master branch has diverged too much, I could not resolve its conflicts. I am closing this in favor of #148, which I had to recreate manually based on your code. Thanks for your help. |
set -u("no unset variables") is a useful shell option that catches a lot of bugs caused by things like misspelled variables. This PR updates all of the Bashly templates to useset -u-safe idioms so it can be set globally for bashly-managed scripts.This is currently a DRAFT: there are some broken things (see PR comments) but filing it here for discussion.