Skip to content

Commit 2817a4b

Browse files
authored
fix(project config manager): Don't log an error when not initialized with datafile (#589)
Summary: Fixes a regression introduced during refactoring for datafile accessor - any time the datafile property of the object passed to createInstance is missing or falsy, the logger will output (for example): [OPTIMIZELY] - ERROR 2020-10-05T23:38:15.224Z CONFIG_VALIDATOR: No datafile specified. Cannot start optimizely Passing in an sdkKey, but no datafile, is valid and supported when calling createInstance, but this message leads the user to believe otherwise. In this situation, nothing is actually wrong, but the message says "Cannot start optimizely". To fix, in ProjectConfigManager __initialize, when config.datafile is falsy, we do not call __handleNewDatafile, avoiding the code path that eventually would log the error message. Test plan: - Added new unit test - Manually tested
1 parent f75c4fb commit 2817a4b

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

packages/optimizely-sdk/CHANGELOG.MD

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010
### Bug fixes
1111

1212
- Fixed return type of `getAllFeatureVariables` method and `dispatchEvent ` method signature of `EventDispatcher` interface in TypeScript type definitions ([#576](https://github.com/optimizely/javascript-sdk/pull/576))
13+
- Don't log an error message when initialized with `sdkKey`, but no `datafile` ([#589](https://github.com/optimizely/javascript-sdk/pull/589))
1314

1415
## [4.3.1] - October 5, 2020
1516

packages/optimizely-sdk/lib/core/project_config/project_config_manager.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,13 @@ ProjectConfigManager.prototype.__initialize = function(config) {
9191
return;
9292
}
9393

94-
var handleNewDatafileException = this.__handleNewDatafile(config.datafile);
95-
if (handleNewDatafileException) {
94+
let handleNewDatafileException;
95+
if (config.datafile) {
96+
handleNewDatafileException = this.__handleNewDatafile(config.datafile);
97+
if (handleNewDatafileException) {
98+
this.__configObj = null;
99+
}
100+
} else {
96101
this.__configObj = null;
97102
}
98103

packages/optimizely-sdk/lib/core/project_config/project_config_manager.tests.js

+7
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,13 @@ describe('lib/core/project_config/project_config_manager', function() {
347347
manager.stop();
348348
sinon.assert.calledOnce(datafileManager.HttpPollingDatafileManager.getCall(0).returnValue.stop);
349349
});
350+
351+
it('does not log an error message', function() {
352+
projectConfigManager.createProjectConfigManager({
353+
sdkKey: '12345',
354+
});
355+
sinon.assert.notCalled(stubLogHandler.log);
356+
});
350357
});
351358

352359
describe('when constructed with sdkKey and with a valid datafile object', function() {

0 commit comments

Comments
 (0)