-
Notifications
You must be signed in to change notification settings - Fork 53
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
Conversation
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(); |
There was a problem hiding this comment.
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}`); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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]>
8b3b012
to
9ac0429
Compare
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.