Skip to content

Validate the path, not the parameter name - #807

Merged
SimonCropp merged 1 commit into
mainfrom
fix-guard-and-path-null
Aug 22, 2026
Merged

Validate the path, not the parameter name#807
SimonCropp merged 1 commit into
mainfrom
fix-guard-and-path-null

Conversation

@SimonCropp

Copy link
Copy Markdown
Member

Guard.FileExists called AgainstEmpty(argumentName, path) - arguments reversed,
so the empty check ran against the literal parameter name, which is never empty.
An empty path fell straight through to ArgumentException("File not found. Path:
") with no ParamName, which names neither the argument nor the file.

The same commit stops OsSettingsResolver dereferencing a null PATH. env -i and
some service launchers do start a process without one, and this runs in a static
constructor, so the NullReferenceException is permanent for the process. An
empty PATH just means no tool is found that way, which is a perfectly good
answer.

No test for the PATH half: it is read once by a type initialiser, so it cannot
be exercised twice in one process.

Guard.FileExists called AgainstEmpty(argumentName, path) - arguments reversed,
so the empty check ran against the literal parameter name, which is never empty.
An empty path fell straight through to ArgumentException("File not found. Path:
") with no ParamName, which names neither the argument nor the file.

The same commit stops OsSettingsResolver dereferencing a null PATH. `env -i` and
some service launchers do start a process without one, and this runs in a static
constructor, so the NullReferenceException is permanent for the process. An
empty PATH just means no tool is found that way, which is a perfectly good
answer.

No test for the PATH half: it is read once by a type initialiser, so it cannot
be exercised twice in one process.
@SimonCropp SimonCropp added this to the 20.0.0 milestone Aug 22, 2026
@SimonCropp
SimonCropp merged commit 2fb7779 into main Aug 22, 2026
10 checks passed
@SimonCropp
SimonCropp deleted the fix-guard-and-path-null branch August 22, 2026 03:24
This was referenced Aug 26, 2026
This was referenced Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant