Skip to content

fix: validate non-empty flag key in Variable<T> - #202

Open
jonathannorris wants to merge 3 commits into
mainfrom
fix/empty-key-validation
Open

fix: validate non-empty flag key in Variable<T>#202
jonathannorris wants to merge 3 commits into
mainfrom
fix/empty-key-validation

Conversation

@jonathannorris

@jonathannorris jonathannorris commented May 4, 2026

Copy link
Copy Markdown
Member

Summary

Validates key in Local Variable<T> and VariableAsync<T>, throwing ArgumentException for null or empty keys.

Motivation

Invalid keys can reach the WASM bucketing engine and trigger AssemblyScript aborts. Repeated failures can corrupt WASM heap state and eventually cause Wasmtime runtime failures. Failing fast at the SDK boundary prevents this path and gives callers a clear exception.

Null defaultValue

Null is valid input for JSON variables, so this also removes the defaultValue null check from DevCycleCloudClient, where it already existed. Variable<T>.DetermineType called variableValue.GetType(), which threw NullReferenceException on a null default; it now falls back to typeof(T).

@jonathannorris
jonathannorris requested a review from a team as a code owner May 4, 2026 14:07
Copilot AI review requested due to automatic review settings May 4, 2026 14:07
@jonathannorris
jonathannorris force-pushed the fix/empty-key-validation branch from 586ae5d to 6fc377b Compare May 4, 2026 14:10

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 adds fail-fast input validation to the Local client’s Variable<T>/VariableAsync<T> APIs to prevent null/empty flag keys (and null defaultValue) from reaching the WASM bucketing engine, aligning Local behavior with the existing Cloud client guards.

Changes:

  • Added ArgumentException guard for null/empty key and ArgumentNullException guard for null defaultValue in DevCycleLocalClient.Variable<T> and VariableAsync<T>.
  • Added MSTest coverage for null/empty key for both sync/async paths, plus a sync-path null defaultValue test.
  • Normalized using System; line (removed prior BOM/formatting artifact) in the test file.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
DevCycle.SDK.Server.Local/Api/DevCycleLocalClient.cs Adds key/defaultValue validation to Local Variable and VariableAsync to prevent invalid inputs reaching WASM.
DevCycle.SDK.Server.Local.MSTests/DevCycleTest.cs Adds tests for null/empty key behavior and null defaultValue behavior (sync path).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread DevCycle.SDK.Server.Local/Api/DevCycleLocalClient.cs Outdated

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

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

Suppressed comments (2)

DevCycle.SDK.Server.Local/Api/DevCycleLocalClient.cs:382

  • ArgumentException is thrown without specifying the parameter name. Providing the paramName improves diagnostics (e.g., "(Parameter 'key')") without changing the exception type or message.
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException("key cannot be null or empty");
            }

DevCycle.SDK.Server.Local/Api/DevCycleLocalClient.cs:313

  • ArgumentException is thrown without specifying the parameter name. Providing the paramName improves diagnostics (e.g., "(Parameter 'key')") without changing the exception type or message.

This issue also appears on line 379 of the same file.

            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException("key cannot be null or empty");
            }

Comment thread DevCycle.SDK.Server.Local/Api/DevCycleLocalClient.cs Outdated
Comment thread DevCycle.SDK.Server.Local/Api/DevCycleLocalClient.cs Outdated
Comment on lines +379 to +382
if (string.IsNullOrEmpty(key))
{
throw new ArgumentException("key cannot be null or empty");
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is/was gated at the WASM layer before - so I'm 50/50 on this - but I do agree it's a good safety net.

…e<T>

Match the existing guards in the Cloud client and the Java/Python SDKs.
Empty/null keys reaching the WASM bucketing engine trigger an internal
abort() at eventQueue.ts:122 ('Event missing target to save aggregate
event') which compiles to a wasmtime trap. After enough traps the AS
heap state becomes corrupted, and on the .NET host wasmtime panics
internally.
@jonathannorris
jonathannorris force-pushed the fix/empty-key-validation branch from 7dc3817 to ca3e4ae Compare August 7, 2026 18:32
@jonathannorris jonathannorris changed the title fix: validate non-empty flag key and non-null defaultValue in Variable<T> fix: validate non-empty flag key in Variable<T> Aug 7, 2026
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.

3 participants