From 0eab22b8fb4466623684e129e700aa0c657cd426 Mon Sep 17 00:00:00 2001 From: Manvendra Date: Thu, 9 Jul 2026 00:28:35 +0530 Subject: [PATCH] fix(install): add Set-StrictMode to install.ps1 rules/powershell/powershell-strict-mode.md, shipped by this repo, opens its "What you do not do" list with: "Ship a .ps1 without `Set-StrictMode -Version Latest` and `$ErrorActionPreference = 'Stop'`." install.ps1 had the second and not the first. It matters here specifically. The script resolves destination paths from variables and then removes and copies directories under them. Without strict mode a misspelled variable expands to $null rather than erroring, and a $null path is exactly the input those Remove-Item / Copy-Item calls must never receive. The existing guards -- Test-Path, -LiteralPath, Join-Path -- are good; strict mode is the one that catches the typo before it reaches them. Its sibling scripts/install.sh already carries `set -euo pipefail` and quotes every expansion, so the shell installer was compliant and the PowerShell one was not. Behavior-preserving. Verified by running both the original and the modified script from the same path with the same arguments in a throwaway worktree: -Target claude/cursor/codex/opencode with -Project, then -Uninstall, all exit 0 under both, with no StrictMode terminating errors. -Help exits 0 and a missing -Target still errors with exit 1. --- scripts/install.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 628316d..4f03236 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -28,6 +28,13 @@ param( [switch]$Help ) +# Fail fast, per rules/powershell/powershell-strict-mode.md. StrictMode turns a +# misspelled variable and a non-existent property into terminating errors instead +# of a silent $null; ErrorActionPreference makes a cmdlet failure stop the script +# rather than letting the next line run on the failure's aftermath. Both matter +# here: this script resolves destination paths from variables and then removes +# and copies directories under them. +Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' function Write-Err($msg) { [Console]::Error.WriteLine($msg) }