Skip to content

fix: clear error when rule Condition is null - #89

Merged
HeyItsGilbert merged 1 commit into
mainfrom
fix/83-null-condition-transform-error
Jul 29, 2026
Merged

fix: clear error when rule Condition is null#89
HeyItsGilbert merged 1 commit into
mainfrom
fix/83-null-condition-transform-error

Conversation

@HeyItsGilbert

@HeyItsGilbert HeyItsGilbert commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #83.

Test-FeatureFlag/Test-Condition threw an opaque You cannot call a method on a null-valued expression error when a rule's Condition was $null (e.g. the Condition key omitted or misspelled). ConditionTransformAttribute.Transform() called .GetType() on the raw input before any of its -is type checks, so a null input never got a chance to hit a meaningful branch.

Fix

  • Classes/FeatureFlag.ps1: ConditionTransformAttribute.Transform() now null-guards up front and throws a clear ArgumentNullException"Rule has no Condition. Each rule must define a 'Condition'." — instead of the opaque binder error.
  • FeatureFlagTransformAttribute.Transform() got the same guard for consistency (identical GetType()-on-null crash risk for a null -FeatureFlag).
  • Added Pester coverage:
    • Test-Condition -Condition $null asserts the new clear message.
    • Test-FeatureFlag with a rule that has no Condition asserts the same.
  • CHANGELOG.md updated.

Verification

Reproduced the exact repro from #83:

Before: Cannot process argument transformation on parameter 'Condition'. You cannot call a method on a null-valued expression.
After:  Cannot process argument transformation on parameter 'Condition'. Rule has no Condition. Each rule must define a 'Condition'. (Parameter 'Condition')

Full build/test (./build.ps1 -Task Test): 368 passed, 0 failed, 5 skipped (pre-existing), Analyze clean (pre-existing informational/warning rules only).

Test-FeatureFlag/Test-Condition threw an opaque 'You cannot call a
method on a null-valued expression' error when a rule's Condition was
$null (omitted or misspelled key). ConditionTransformAttribute called
.GetType() on the null input before any of its type checks ran.

ConditionTransformAttribute.Transform() now null-guards up front and
throws a clear ArgumentNullException naming the problem: the rule must
define a Condition. FeatureFlagTransformAttribute gained the same
null guard for consistency (same GetType()-on-null pattern for a null
-FeatureFlag).

Added coverage: Test-Condition -Condition $null, and a Test-FeatureFlag
rule with no Condition, both assert the new clear error message.
Copilot AI review requested due to automatic review settings July 29, 2026 04:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves Gatekeeper’s argument transformation error handling so malformed feature flag rules (specifically missing/null Condition) fail with a clear, actionable ArgumentNullException message instead of an opaque null-method invocation error.

Changes:

  • Added upfront $null guards in ConditionTransformAttribute.Transform() and FeatureFlagTransformAttribute.Transform() to avoid .GetType()-on-null crashes and emit clearer errors.
  • Added Pester coverage for Test-Condition -Condition $null and for Test-FeatureFlag evaluating a rule with a missing Condition.
  • Documented the fix in CHANGELOG.md.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
Gatekeeper/Classes/FeatureFlag.ps1 Adds null guards in argument transformation attributes to produce clear exceptions for null Condition / FeatureFlag.
tests/Test-FeatureFlag.tests.ps1 Adds a regression test ensuring a rule missing Condition throws a clear error during Test-FeatureFlag.
tests/Classes.tests.ps1 Adds a regression test ensuring Test-Condition -Condition $null throws a clear error.
CHANGELOG.md Notes the behavior change and references issue #83.

Comment on lines +265 to +268
if ($null -eq $inputData) {
throw [System.ArgumentNullException]::new('Condition',
"Rule has no Condition. Each rule must define a 'Condition'.")
}
Comment on lines +239 to +242
if ($null -eq $inputData) {
throw [System.ArgumentNullException]::new('FeatureFlag',
"FeatureFlag cannot be null.")
}
@github-actions

Copy link
Copy Markdown

Test Results

    4 files    448 suites   12s ⏱️
  379 tests   374 ✅  5 💤 0 ❌
1 492 runs  1 466 ✅ 26 💤 0 ❌

Results for commit 13a5b4f.

@HeyItsGilbert
HeyItsGilbert merged commit 5d95a9a into main Jul 29, 2026
10 checks passed
@HeyItsGilbert
HeyItsGilbert deleted the fix/83-null-condition-transform-error branch July 29, 2026 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test-FeatureFlag: a rule with a null Condition throws an opaque transform error

2 participants