fix(hooks): initialize PUA_LANGUAGE to avoid unbound variable under set -u#145
Open
zhengjxu wants to merge 1 commit intotanweai:mainfrom
Open
fix(hooks): initialize PUA_LANGUAGE to avoid unbound variable under set -u#145zhengjxu wants to merge 1 commit intotanweai:mainfrom
zhengjxu wants to merge 1 commit intotanweai:mainfrom
Conversation
…et -u PUA_LANGUAGE is only assigned inside the 'if [ -f $config ]' block, but referenced unconditionally at line 180 (the Chinese-language override). When ~/.pua/config.json does not exist (fresh install) and the hook runs under set -u, flavor-helper.sh aborts with: flavor-helper.sh: line 180: PUA_LANGUAGE: unbound variable Initialize to empty string at the top of get_flavor(); respects any externally-set value and falls through all Chinese-override branches correctly when empty.
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.
Problem
When
~/.pua/config.jsondoes not exist (fresh install — user never ran/pua:surveyor customized flavor),hooks/flavor-helper.shfails with:PUA_LANGUAGEis only assigned inside theif [ -f "$config" ]block (line 12), but referenced unconditionally at line 180 (the Chinese-language override check). Hooks running underset -u/set -euabort on the unbound variable.Repro
Fix
One line at the top of
get_flavor():get_flavor() { local config="${HOME:-~}/.pua/config.json" local raw_flavor="" + PUA_LANGUAGE="${PUA_LANGUAGE:-}"${PUA_LANGUAGE:-}respects any externally-set value and defaults to empty string otherwise. An empty value falls through all the Chinese-override branches correctly (they compare against"zh"/"中文").Verification
Both fresh-install (no config file) and normal paths pass under
set -eu.