From a960a00a58201cfa693b48609f58e8362588e25d Mon Sep 17 00:00:00 2001 From: Steven Zhang Date: Thu, 8 Jan 2026 14:55:19 -0600 Subject: [PATCH] fix: browser logging was inconsistent --- .../__tests__/LDClientImpl.variation.test.ts | 12 ++++++------ packages/shared/sdk-client/src/LDClientImpl.ts | 6 ++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/shared/sdk-client/__tests__/LDClientImpl.variation.test.ts b/packages/shared/sdk-client/__tests__/LDClientImpl.variation.test.ts index d6fbd74b90..958c4d9baa 100644 --- a/packages/shared/sdk-client/__tests__/LDClientImpl.variation.test.ts +++ b/packages/shared/sdk-client/__tests__/LDClientImpl.variation.test.ts @@ -69,21 +69,21 @@ describe('sdk-client object', () => { expect(devTestFlag).toBe(true); }); - test('variation flag not found', async () => { + test('variation flag not found should give a warning message', async () => { await ldc.identify({ kind: 'user', key: 'test-user' }); const errorListener = jest.fn().mockName('errorListener'); ldc.on('error', errorListener); const p = ldc.identify(context); - ldc.variation('does-not-exist', 'not-found'); + const flagValue = ldc.variation('does-not-exist', 'not-found'); await expect(p).resolves.toBeUndefined(); - expect(errorListener).toHaveBeenCalledTimes(1); - const error = errorListener.mock.calls[0][1]; - expect(error.message).toMatch(/unknown feature/i); + + expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('Unknown feature')); + expect(flagValue).toBe('not-found'); }); - test('variationDetail flag not found', async () => { + test('variationDetail flag not found should return an error detail', async () => { await ldc.identify(context); const flag = ldc.variationDetail('does-not-exist', 'not-found'); diff --git a/packages/shared/sdk-client/src/LDClientImpl.ts b/packages/shared/sdk-client/src/LDClientImpl.ts index 71bca2293f..039153a541 100644 --- a/packages/shared/sdk-client/src/LDClientImpl.ts +++ b/packages/shared/sdk-client/src/LDClientImpl.ts @@ -543,11 +543,9 @@ export default class LDClientImpl implements LDClient, LDClientIdentifyResult { if (foundItem === undefined || foundItem.flag.deleted) { const defVal = defaultValue ?? null; - const error = new LDClientError( - `Unknown feature flag "${flagKey}"; returning default value ${defVal}.`, - ); - this.emitter.emit('error', this._activeContextTracker.getUnwrappedContext(), error); + this.logger?.warn(`Unknown feature flag "${flagKey}"; returning default value ${defVal}.`); + if (hasContext) { this._eventProcessor?.sendEvent( this._eventFactoryDefault.unknownFlagEvent(flagKey, defVal, evalContext),