fix: handle invalid selector errors#1976
Conversation
✅ Deploy Preview for polite-licorice-3db33c canceled.
|
8e8b5fd to
d79d9be
Compare
There was a problem hiding this comment.
Code Review
This pull request refactors the Selector creation and manipulation. NewSelector now validates selector keys and returns an error for invalid keys, with corresponding error handling added across evaluation and sync services. Additionally, generic WithIndex calls are replaced with type-safe methods like WithSource and WithFlagSetId. The review feedback recommends two improvements: recording the error on the tracing span when startResolveV2 fails in flag_evaluator_v2.go, and setting exitReason = "error" when returning an invalid selector error in flag-sync/handler.go to ensure accurate metrics.
75e6aff to
9a39218
Compare
|
@alxckn unit test for
Otherwise this can regress silently. WDYT? Also FYI, some of the sonar issues should be fixed on |
Signed-off-by: Alexandre Chakroun <achakroun@macmail.fr>
Signed-off-by: Alexandre Chakroun <achakroun@macmail.fr>
Signed-off-by: Alexandre Chakroun <achakroun@macmail.fr>
Signed-off-by: Alexandre Chakroun <achakroun@macmail.fr>
Signed-off-by: Alexandre Chakroun <achakroun@macmail.fr>
9a39218 to
b353b2e
Compare
Signed-off-by: Alexandre Chakroun <achakroun@macmail.fr>
|
|
@toddbaert thanks for the review. I took care of comments, added integration tests to prevent regressions, and the sonar warnings seem resolved 👍 |



This PR
Invalid selector expressions in the
flagd-selectorheader were causing unhandled errors that surfaced as 500 responses. This PR validates the selector at parse time and maps invalid input to the appropriate error code(
InvalidArgument/ HTTP 400) across all service layers (flag evaluation, flag sync, OFRep).As part of this fix, the
Selectorconstruction API has been redesigned to eliminate unchecked string-based construction entirely:NewSelector(expr string)now returns an error for unknown keysWithIndexis removed (breaking change) — replaced by typed methodsWithSourceandWithFlagSetIdwhich cannot produce an invalid selectorRelated Issues
Notes
Breaking change:
(Selector).WithIndex(key, value string)has been removed from the public API. Callers should migrate toSelector{}.WithSource(source)orSelector{}.WithFlagSetId(id).(with AI help)