Skip to content

Commit 9bbd265

Browse files
committed
review comments
1 parent abb62d4 commit 9bbd265

File tree

6 files changed

+25
-34
lines changed

6 files changed

+25
-34
lines changed

packages/common_client/lib/src/context_modifiers/anonymous_context_modifier.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ final class AnonymousContextModifier implements ContextModifier {
2020
@override
2121
Future<LDContext> decorate(LDContext context) async {
2222
if (!context.valid) {
23-
_logger.info(
23+
_logger.warn(
2424
'AnonymousContextModifier was asked to modify an invalid context and will attempt to do so. This is expected if starting with an empty context.');
2525
}
2626
// Before we make a builder we should check if any anonymous contexts

packages/common_client/lib/src/context_modifiers/env_context_modifier.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final class AutoEnvContextModifier implements ContextModifier {
4343
@override
4444
Future<LDContext> decorate(LDContext context) async {
4545
if (!context.valid) {
46-
_logger.info(
46+
_logger.warn(
4747
'AutoEnvContextModifier was asked to modify an invalid context and will attempt to do so. This is expected if starting with an empty context.');
4848
}
4949

packages/common_client/lib/src/ld_common_client.dart

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ final class LDCommonClient {
131131

132132
late final DataSourceManager _dataSourceManager;
133133
late final EnvironmentReport _envReport;
134-
late final AsyncSingleQueue<IdentifyResult> _identifyQueue =
135-
AsyncSingleQueue();
134+
late final AsyncSingleQueue<void> _identifyQueue = AsyncSingleQueue();
136135
late final DataSourceFactoriesFn _dataSourceFactories;
137136

138137
// Modifications will happen in the order they are specified in this list.
@@ -275,7 +274,7 @@ final class LDCommonClient {
275274
// having been set resulting in a crash.
276275
_identifyQueue.execute(() async {
277276
await _startInternal();
278-
return _identifyInternal(_initialUndecoratedContext,
277+
await _identifyInternal(_initialUndecoratedContext,
279278
waitForNetworkResults: waitForNetworkResults);
280279
}).then((res) {
281280
_startCompleter!.complete(_mapIdentifyResult(res));
@@ -422,52 +421,46 @@ final class LDCommonClient {
422421
return IdentifyError(Exception(message));
423422
}
424423
final res = await _identifyQueue.execute(() async {
425-
return _identifyInternal(context,
424+
await _identifyInternal(context,
426425
waitForNetworkResults: waitForNetworkResults);
427426
});
428427
return _mapIdentifyResult(res);
429428
}
430429

431-
Future<IdentifyResult> _mapIdentifyResult(
432-
TaskResult<IdentifyResult> res) async {
430+
Future<IdentifyResult> _mapIdentifyResult(TaskResult<void> res) async {
433431
switch (res) {
434-
case TaskComplete<IdentifyResult>(result: var result):
435-
return result ?? IdentifyComplete();
436-
case TaskShed<IdentifyResult>():
432+
case TaskComplete<void>():
433+
return IdentifyComplete();
434+
case TaskShed<void>():
437435
return IdentifySuperseded();
438-
case TaskError<IdentifyResult>(error: var error):
436+
case TaskError<void>(error: var error):
439437
return IdentifyError(error);
440438
}
441439
}
442440

443-
Future<IdentifyResult> _identifyInternal(LDContext context,
441+
Future<void> _identifyInternal(LDContext context,
444442
{bool waitForNetworkResults = false}) async {
445443
if (!context.valid) {
446444
const message =
447445
'LDClient was provided an invalid context. The context will be ignored. Existing flags will be used for evaluations until identify is called with a valid context.';
448446
_logger.warn(message);
449-
return IdentifyError(Exception(message));
447+
throw Exception(message);
450448
}
451449

452-
try {
453-
await _setAndDecorateContext(context);
454-
final completer = Completer<void>();
455-
_eventProcessor?.processIdentifyEvent(IdentifyEvent(context: _context));
456-
final loadedFromCache = await _flagManager.loadCached(_context);
450+
await _setAndDecorateContext(context);
451+
final completer = Completer<void>();
452+
_eventProcessor?.processIdentifyEvent(IdentifyEvent(context: _context));
453+
final loadedFromCache = await _flagManager.loadCached(_context);
457454

458-
if (_config.offline) {
459-
return IdentifyComplete();
460-
}
461-
_dataSourceManager.identify(_context, completer);
455+
if (_config.offline) {
456+
return;
457+
}
458+
_dataSourceManager.identify(_context, completer);
462459

463-
if (loadedFromCache && !waitForNetworkResults) {
464-
return IdentifyComplete();
465-
}
466-
await completer.future;
467-
return IdentifyComplete();
468-
} catch (error) {
469-
return IdentifyError(error);
460+
if (loadedFromCache && !waitForNetworkResults) {
461+
return;
470462
}
463+
return completer.future;
471464
}
472465

473466
/// Returns the value of flag [flagKey] for the current context as a bool.

packages/common_client/test/context_decorators/anonymous_context_modifier_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void main() {
136136

137137
final logRecord = verify(() => mockAdapter.log(captureAny())).captured[0]
138138
as LDLogRecord;
139-
expect(logRecord.level, LDLogLevel.info);
139+
expect(logRecord.level, LDLogLevel.warn);
140140
expect(logRecord.message,
141141
'AnonymousContextModifier was asked to modify an invalid context and will attempt to do so. This is expected if starting with an empty context.');
142142
});

packages/common_client/test/context_decorators/env_context_modifier_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ void main() {
487487

488488
final logRecord = verify(() => mockAdapter.log(captureAny())).captured[0]
489489
as LDLogRecord;
490-
expect(logRecord.level, LDLogLevel.info);
490+
expect(logRecord.level, LDLogLevel.warn);
491491
expect(logRecord.message,
492492
'AutoEnvContextModifier was asked to modify an invalid context and will attempt to do so. This is expected if starting with an empty context.');
493493
});

packages/event_source_client/lib/src/sse_client_html.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,3 @@ SSEClient getSSEClient(
121121
EventSourceLogger? logger) =>
122122
// dropping unsupported configuration options
123123
HtmlSseClient(uri, eventTypes, logger);
124-
125-
// TODO: see if logging can be piped through to html source

0 commit comments

Comments
 (0)