Skip to content

Commit

Permalink
Add feature flag name as part of the readiness warning log message
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilianoSanchez committed Oct 20, 2023
1 parent cb28e51 commit 4dfd27f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/logger/messages/warn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const codesWarn: [number, string][] = codesError.concat([
[c.SUBMITTERS_PUSH_FAILS, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Dropping %s after retry. Reason: %s.'],
[c.SUBMITTERS_PUSH_RETRY, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Failed to push %s, keeping data to retry on next iteration. Reason: %s.'],
// client status
[c.CLIENT_NOT_READY, '%s: the SDK is not ready, results may be incorrect. Make sure to wait for SDK readiness before using this method.'],
[c.CLIENT_NOT_READY, '%s: the SDK is not ready, results may be incorrect%s. Make sure to wait for SDK readiness before using this method.'],
[c.CLIENT_NO_LISTENER, 'No listeners for SDK Readiness detected. Incorrect control treatments could have been logged if you called getTreatment/s while the SDK was not yet ready.'],
// input validation
[c.WARN_SETTING_NULL, '%s: Property "%s" is of invalid type. Setting value to null.'],
Expand Down
2 changes: 1 addition & 1 deletion src/sdkClient/clientInputValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
const attributes = validateAttributes(log, maybeAttributes, methodName);
const isNotDestroyed = validateIfNotDestroyed(log, readinessManager, methodName);

validateIfOperational(log, readinessManager, methodName);
validateIfOperational(log, readinessManager, methodName, splitOrSplits);

const valid = isNotDestroyed && key && splitOrSplits && attributes !== false;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/inputValidation/__tests__/isOperational.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('validateIfOperational', () => {
expect(validateIfOperational(loggerMock, readinessManagerMock, 'test_method')).toBe(false); // It should return true if SDK was ready.
expect(readinessManagerMock.isReady).toBeCalledTimes(1); // It checks for SDK_READY status.
expect(readinessManagerMock.isReadyFromCache).toBeCalledTimes(1); // It checks for SDK_READY_FROM_CACHE status.
expect(loggerMock.warn).toBeCalledWith(CLIENT_NOT_READY, ['test_method']); // It should log the expected warning.
expect(loggerMock.warn).toBeCalledWith(CLIENT_NOT_READY, ['test_method', '']); // It should log the expected warning.
expect(loggerMock.error).not.toBeCalled(); // But it should not log any errors.
});
});
4 changes: 2 additions & 2 deletions src/utils/inputValidation/isOperational.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export function validateIfNotDestroyed(log: ILogger, readinessManager: IReadines
return false;
}

export function validateIfOperational(log: ILogger, readinessManager: IReadinessManager, method: string) {
export function validateIfOperational(log: ILogger, readinessManager: IReadinessManager, method: string, featureFlagNameOrNames?: string | string[] | false) {
if (readinessManager.isReady() || readinessManager.isReadyFromCache()) return true;

log.warn(CLIENT_NOT_READY, [method]);
log.warn(CLIENT_NOT_READY, [method, featureFlagNameOrNames ? ` for feature flag ${featureFlagNameOrNames.toString()}` : '']);
return false;
}

0 comments on commit 4dfd27f

Please sign in to comment.