Add set -euo pipefail to shell scripts#207
Closed
cluster2600 wants to merge 1 commit intoNVIDIA:mainfrom
Closed
Conversation
Enable strict error handling across all shell scripts in the repository. Scripts that already had partial coverage (set -e, set -eo pipefail, set -Eo pipefail) are upgraded to include the -u flag for unbound variable detection. Scripts with no error handling at all now have set -euo pipefail added after the shebang line. For aws/sagemaker/launch.sh which uses #!/bin/sh, set -eu is used instead since pipefail is not POSIX-portable. Three scripts that were missing shebangs (_nvcf_creation.sh, _nvcf_deploy.sh, create-secrets.sh) also get #!/bin/bash added. The only .sh file left untouched is the Helm library_chart script.sh which is an empty template containing only licence headers. Closes NVIDIA#142 Signed-off-by: Maxime Grenu <maxime.grenu@gmail.com>
Author
|
Closing — no response after 3 weeks. |
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.
Summary
Addresses #142 — enables strict error handling across all shell scripts in the repository.
set -e,set -eo pipefail,set -Eo pipefail) are upgraded to include the-uflag for unbound variable detectionset -x(debug tracing) now also getset -euo pipefailadded before the existingset -xlineset -euo pipefailinserted after the shebang line_nvcf_creation.sh,_nvcf_deploy.sh,create-secrets.sh) also recieve a#!/bin/bashheaderaws/sagemaker/launch.shuses#!/bin/sh, so it getsset -euinstead sincepipefailis not POSIX-portable.shfile left untouched is the Helmlibrary_chart/files/script.shwhich is an empty template containing only licence headers and a comment — it has no actual commandsBreakdown by change type
set -eupgraded toset -euo pipefailset -eo pipefailupgraded toset -euo pipefailset -Eo pipefailupgraded toset -Euo pipefailset -euo pipefailadded (wasset -xonly)set -euo pipefailadded (no priorsetflags)set -euadded (#!/bin/shscript)set -euo pipefailadded (no shebang existed)This should not change any existing behaviour for scripts that were already succeeding — the new flags only cause earlier, louder failures when something goes wrong, which is the recognised best practice for shell scripting.
Test plan
bash -nagainst each.shfile)set -euo pipefailis placed correctly relative to shebangs and licence headersaws/sagemaker/launch.shusesset -eu(notpipefail) since it targets/bin/sh