padosoft-cross-platform-scriptinglisted
Install: claude install-skill padosoft/skills
# Cross-platform scripting
The script runs on a Windows workstation and on a Linux runner. Everything below is a way those two disagree
**silently** — the script does not crash, it reports success while having done something else.
---
## 1. Exit codes: capture each one, immediately
```powershell
# ❌ only the last command's status is checked — the first failure is invisible
tool-a ; tool-b ; if ($LASTEXITCODE -ne 0) { exit 1 }
# ✅
tool-a ; $a = $LASTEXITCODE
tool-b ; $b = $LASTEXITCODE
if ($a -ne 0 -or $b -ne 0) { exit 1 }
```
Two traps, both from the same variable:
- **It persists.** `$LASTEXITCODE` keeps the value of the last native command run anywhere in the script,
**even when that failure was handled** and the script went on to succeed. A wrapper that propagates it at
the end turns a handled error into a failed job.
- **A non-terminating error is not a failure** in PowerShell: suppressing the *message* does not change the
status, and conversely a cmdlet that "failed" may leave the previous native exit code untouched.
In POSIX shell the equivalents are `set -o pipefail` (a failing command mid-pipe is otherwise invisible) and
checking `${PIPESTATUS[@]}` when you need each stage.
## 2. Never parse another tool's human output
An error renderer is a UI: it carries ANSI codes, wraps lines where the terminal ends, and inserts context
between the message and the path. Stripping ANSI is not enough, because the line breaks are the renderer's
too, and they move when