Skip to content

Commit ffc1638

Browse files
kazuponfengmk2
andauthored
fix(cli): handle permission errors when configuring shell PATH (#1040)
## Summary resolve #1034 - Add write permission check in `install.sh` `add_bin_to_path`: exits immediately with a clear error message when shell config files (`.zshenv`, `.zshrc`, etc.) are not writable, instead of silently failing and showing misleading success output - Add `try/catch` around `SetEnvironmentVariable` in `install.ps1` `Configure-UserPath`: exits with an actionable error message when PATH update fails --------- Co-authored-by: MK (fengmk2) <fengmk2@gmail.com>
1 parent 521ca87 commit ffc1638

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

packages/cli/install.ps1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,13 @@ function Configure-UserPath {
178178
}
179179

180180
$newPath = "$binPath;$userPath"
181-
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
182-
$env:Path = "$binPath;$env:Path"
183-
return "true"
181+
try {
182+
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
183+
$env:Path = "$binPath;$env:Path"
184+
return "true"
185+
} catch {
186+
Write-Error-Exit "Cannot update user PATH. Please check your system permissions and re-run the installer."
187+
}
184188
}
185189

186190
# Run vp env setup --refresh, showing output only on failure

packages/cli/install.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ add_bin_to_path() {
325325
ref_pattern=$(printf '%s' "$INSTALL_DIR_REF" | sed 's/[.[\*^$()+?{|]/\\&/g')
326326

327327
if [ -f "$shell_config" ]; then
328+
if [ ! -w "$shell_config" ]; then
329+
warn "Cannot write to $shell_config (permission denied), skipping."
330+
return 1
331+
fi
328332
if grep -q "${abs_pattern}/env" "$shell_config" 2>/dev/null || \
329333
grep -q "${ref_pattern}/env" "$shell_config" 2>/dev/null; then
330334
return 2

0 commit comments

Comments
 (0)