init-session.ps1 reports success after a denied file write because Out-File errors are non-terminating
Problem
init-session.ps1 prints Created task_plan.md and Planning files initialized! even when the write of a planning file was denied. The files are then missing while the output claims success.
Scope: Windows, both root mode and named-plan mode, but only when the target directory refuses the write (an ACL deny, a read-only mount, a locked file). In a normal writable project the files are created as expected.
How to reproduce
mkdir denied; cd denied
icacls . /deny "$env:USERNAME:(W)"
..\scripts\init-session.ps1
icacls . /remove:d "$env:USERNAME"Observed with pwsh 7.6.6 and Windows PowerShell 5.1: red Out-File : Access to the path ... is denied lines, followed by Created task_plan.md, Created findings.md, Created progress.md and Planning files initialized!, exit code 0. No planning file exists.
Cause: skills/planning-with-files/scripts/init-session.ps1 writes each template with ... | Out-File -LiteralPath $Path -Encoding UTF8 and then prints the success line unconditionally. Out-File raises a non-terminating error, and the script does not set $ErrorActionPreference = 'Stop' or test $? after the write.
The shell twin runs under set -e, so a failed redirect aborts before the success message.
Suggested fix
One of:
- Set
$ErrorActionPreference = 'Stop'at the top ofinit-session.ps1(check that the existingtry/catchblocks around the selector and attestation calls still behave as intended). - Add
-ErrorAction Stopto eachOut-File/Set-Contentcall, or test$?after each write and exit 1 with a clear message.
In named-plan mode the failed run should also not leave a half-initialised plan directory behind, or at least should say so.
A regression test can deny write access in a temporary directory with icacls (Windows only, skip elsewhere) and assert a non-zero exit code and no success line.
Origin
Found by the v3.19.0 release review (PRs #247, #248, #249). Pre-existing behaviour, not introduced by that release. Tracked as item 3 of #250 before that issue was split into one issue per item.
Source: OthmanAdi/planning-with-files