fix: validate non-empty flag key in Variable<T> - #202
Conversation
586ae5d to
6fc377b
Compare
There was a problem hiding this comment.
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
ArgumentExceptionguard for null/emptykeyandArgumentNullExceptionguard for nulldefaultValueinDevCycleLocalClient.Variable<T>andVariableAsync<T>. - Added MSTest coverage for null/empty key for both sync/async paths, plus a sync-path null
defaultValuetest. - 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.
7356a2c to
7dc3817
Compare
There was a problem hiding this comment.
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");
}
| if (string.IsNullOrEmpty(key)) | ||
| { | ||
| throw new ArgumentException("key cannot be null or empty"); | ||
| } |
There was a problem hiding this comment.
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.
7dc3817 to
ca3e4ae
Compare
Summary
Validates
keyin LocalVariable<T>andVariableAsync<T>, throwingArgumentExceptionfor 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
defaultValuenull check fromDevCycleCloudClient, where it already existed.Variable<T>.DetermineTypecalledvariableValue.GetType(), which threwNullReferenceExceptionon a null default; it now falls back totypeof(T).