Skip to content

Conversation

@kylejuliandev
Copy link
Contributor

@kylejuliandev kylejuliandev commented Jan 14, 2026

This PR

JsonLogic returns the whole key even when the targeting hasn't been matched. For example, invalid is the key but the targeting is not valid so the whole json string gets returned. This causes the provider to return a Flag not found response (although the flag has been found, the targeting is just invalid). I found this while adding support in the flagd e2e tests for the targeting.feature and found the provider not returning the correct response.

{
    "flags": {
        "error-targeting-flag": {
            "defaultVariant": "two",
            "state": "ENABLED",
            "targeting": {
                "invalid": [
                    "this is not valid targeting"
                ]
            },
            "variants": {
                "one": 1,
                "two": 2
            }
        }
    }
}

Related Issues

Notes

Follow-up Tasks

How to test

Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
@kylejuliandev kylejuliandev added the provider:flagd Issues related to provider flagd label Jan 14, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kylejuliandev, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the flag evaluation logic within the flagd provider to accurately detect and report invalid targeting configurations. By introducing explicit checks for primitive JsonLogic evaluation results and robust exception handling, it ensures that flags with malformed targeting rules, such as those using non-primitive keys, correctly trigger a ParseError. This enhancement improves the diagnostic capabilities and reliability of the flag resolution process.

Highlights

  • Improved Error Handling for Invalid Targeting: The system now explicitly throws a "ParseError" when a flag's targeting rule is invalid, specifically when the JsonLogic evaluation results in a non-primitive type (like an object or array) for a variant selector.
  • Enhanced Robustness in JsonLogic Evaluation: A try-catch block has been added around the JsonLogic.Apply method to gracefully handle exceptions during rule processing, converting them into a FeatureProviderException with ErrorType.ParseError.
  • Corrected Flag Evaluation Response: This fix prevents scenarios where an invalid targeting configuration would previously lead to an incorrect "Flag not found" response, instead providing a more accurate ParseError.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses an issue where invalid targeting rules in flagd were not producing a parse error. The added validation for the JsonLogic evaluation result is a good improvement. My review includes a suggestion to fix a bug in the handling of null evaluation results and to refactor the logic for better readability. I've also included a minor point about catching generic exceptions.

Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
@kylejuliandev kylejuliandev marked this pull request as ready for review January 14, 2026 19:58
@kylejuliandev kylejuliandev requested review from a team as code owners January 14, 2026 19:58
@chrfwow
Copy link
Contributor

chrfwow commented Jan 15, 2026

Could you please add a test to verify the new behaviour is what we expect?

@kylejuliandev
Copy link
Contributor Author

kylejuliandev commented Jan 15, 2026

Could you please add a test to verify the new behaviour is what we expect?

Yep will add it later today! It was late last night 😆

Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
@askpt askpt requested a review from chrfwow January 15, 2026 21:05
This was referenced Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

provider:flagd Issues related to provider flagd

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants