Skip to content

fix: init in-process error, throw on invalid rules #767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 14, 2024

Conversation

toddbaert
Copy link
Member

@toddbaert toddbaert commented Feb 13, 2024

  • fixes an unhandled error if sync source not available at startup
  • throws on invalid targeting rules as per flagd spec
  • adds additional e2e tests

Implements the latest e2e tests, including those added here. Here we decided that invalid targeting should throw, which required a small change in core.

I also found a bug on the in-process provider where there's an unhandled exception in startup.

Comment on lines +229 to +234
it('should throw with invalid targeting rules', () => {
const core = new FlagdCore();
const flagCfg = `{"flags":{"isEnabled":{"state":"ENABLED","variants":{"true":true,"false":false},"defaultVariant":"false","targeting":{"invalid": ["this is not valid targeting"]}}}}`;
core.setConfigurations(flagCfg);

expect(() => core.resolveBooleanEvaluation('isEnabled', false, {}, console)).toThrow();
Copy link
Member Author

Choose a reason for hiding this comment

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

New unit test for e2e test I mentioned.

@@ -165,8 +165,7 @@ export class FlagdCore implements Storage {
try {
targetingResolution = this._targeting.applyTargeting(flagKey, flag.targeting, evalCtx);
} catch (e) {
logger.error(`Error evaluating targeting rule for flag ${flagKey}, falling back to default`, e);
targetingResolution = null;
throw new GeneralError(`Error evaluating targeting rule for flag ${flagKey}: ${(e as Error)?.message}`);
Copy link
Member Author

@toddbaert toddbaert Feb 13, 2024

Choose a reason for hiding this comment

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

non-test change 1: throw if targeting throws, as per flagd test specs

@@ -70,39 +70,67 @@ export class GrpcFetch implements DataFetch {
) {
this._logger?.debug('Starting gRPC sync connection');
closeStreamIfDefined(this._syncStream);
this._syncStream = this._syncClient.syncFlags(this._request);
Copy link
Member Author

@toddbaert toddbaert Feb 13, 2024

Choose a reason for hiding this comment

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

non-test change 2: This can throw before it ever connects, which resulted in an unhandled exception... when that happens the .on('error') handler never takes effect. This is fixed by making the catch and .on('error') both share a local method (handleError).

As you can see, all reconnect e2e tests still work with this change.

* fixes an unhandled error if sync source not available at startup
* throws on invalid targeting rules as per flagd spec

Signed-off-by: Todd Baert <[email protected]>
Signed-off-by: Todd Baert <[email protected]>
@toddbaert toddbaert force-pushed the chore/update-e2e-tests branch from 8b3b012 to 9ac0429 Compare February 13, 2024 23:29
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.

4 participants