-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Gracefully handle unbound parameters #1903
Conversation
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.
Small nit that the tests picked up- great idea and great work @gaelicWizard !
I've rebased on current master branch. Anything else needed for this PR? 😃 |
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.
nice job!
I have a question though- how can we prevent new PRs from adding new unbound parameters?
we should have a test that will fail this kind of thing- what do you think @gaelicWizard ?
I found a StackOverflow q/a which includes an example of an unbound parameter failing to fail a |
If you add |
I've rebased on current master, but I haven't had time to do BATS yet. 😃 |
I think that we should just open an issue about it. No need to clutter this PR with even more changes. |
If the user hasn't defined BASH_IT_LOG_LEVEL, then the integer comparison fails. Handle it by defaulting to '1'. If lib/log is loaded improperly, the BASH_IT_LOG_PREFIX may be undefined. Unlikely, but no harm in handling it too. Likewise, if no theme is loaded, then $echo_green, $echo_normal, et al are not defined.
If $BASH_PREVIEW is unset, treat it as blank.
Handle BASH_IT, BASH_IT_OLD_BASH_SETUP, BASH_IT_THEME, BASH_THEME, and PROMPT.
Expressly deal with if $echo_yellow hasn’t been defined
Expressly handle unbound $BASH_IT_GREP when testing for value
Expressly handle $BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE being not-set as being blank.
Expressly handle $BASH_IT_REMOTE as blank when variable is not set.
Expressly handle as blank when $BASH_IT_LEGACY_PASS is not set.
Give up and accept defeat that bash-completion can't reasonably be audited for unbound parameters. Wrap invocation with disabling strictness, and restore after if it was enabled.
Set the default when BASH_IT_LOG_LEVEL is unbound to log level none: no warnings or errors are reported at all.
It has come to my attention that this entire branch and my work would have been wholly unneeded if only the |
Description
Expressly handle parameter values as empty when the parameter is not set at all, instead of letting comparisons fail for missing arguments. Change$BASH_PREVIEW to "$ {BASH_PREVIEW:-}" and similar for $BASH_IT_LOG_PREFIX, $BASH_IT_LOG_LEVEL, &c. This helps towards #1696.
Motivation and Context
This reduces errors by explicitly testing for blank values rather than silent syntax errors. I'm very careful about what code I allow to run, and I use
set -u
to ensure that I'm not inadvertently confusing an edge-case when scripting. There's a lot of unbound variables here.How Has This Been Tested?
This is my live branch in use on my own system now.
Types of changes
Checklist:
clean_files.txt
and formatted it usinglint_clean_files.sh
.