Skip to content

Commit 32a592a

Browse files
[FSSDK-10935] error log adjustment
1 parent bbe7a5b commit 32a592a

File tree

28 files changed

+293
-246
lines changed

28 files changed

+293
-246
lines changed

lib/core/audience_evaluator/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import fns from '../../utils/fns';
1919
import {
2020
LOG_LEVEL,
2121
LOG_MESSAGES,
22-
ERROR_MESSAGES,
2322
} from '../../utils/enums';
2423
import * as conditionTreeEvaluator from '../condition_tree_evaluator';
2524
import * as customAttributeConditionEvaluator from '../custom_attribute_condition_evaluator';
2625
import * as odpSegmentsConditionEvaluator from './odp_segment_condition_evaluator';
2726
import { Audience, Condition, OptimizelyUserContext } from '../../shared_types';
27+
import { CONDITION_EVALUATOR_ERROR } from '../../error_messages';
2828

2929
const logger = getLogger();
3030
const MODULE_NAME = 'AUDIENCE_EVALUATOR';
@@ -112,7 +112,7 @@ export class AudienceEvaluator {
112112
} catch (err: any) {
113113
logger.log(
114114
LOG_LEVEL.ERROR,
115-
ERROR_MESSAGES.CONDITION_EVALUATOR_ERROR, MODULE_NAME, condition.type, err.message
115+
CONDITION_EVALUATOR_ERROR, MODULE_NAME, condition.type, err.message
116116
);
117117
}
118118

lib/core/bucketer/index.tests.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
import { createLogger } from '../../plugins/logger';
2828
import projectConfig from '../../project_config/project_config';
2929
import { getTestProjectConfig } from '../../tests/test_data';
30+
import { INVALID_BUCKETING_ID, INVALID_GROUP_ID } from '../../error_messages';
3031

3132
var buildLogMessageFromArgs = args => sprintf(args[1], ...args.splice(2));
3233
var testData = getTestProjectConfig();
@@ -225,7 +226,7 @@ describe('lib/core/bucketer', function () {
225226

226227
assert.throws(function () {
227228
bucketer.bucket(bucketerParamsWithInvalidGroupId);
228-
}, sprintf(ERROR_MESSAGES.INVALID_GROUP_ID, 'BUCKETER', '6969'));
229+
}, sprintf(INVALID_GROUP_ID, 'BUCKETER', '6969'));
229230
});
230231
});
231232

@@ -357,8 +358,8 @@ describe('lib/core/bucketer', function () {
357358
bucketer._generateBucketValue(null);
358359
} );
359360
expect([
360-
sprintf(ERROR_MESSAGES.INVALID_BUCKETING_ID, 'BUCKETER', null, "Cannot read property 'length' of null"), // node v14
361-
sprintf(ERROR_MESSAGES.INVALID_BUCKETING_ID, 'BUCKETER', null, "Cannot read properties of null (reading \'length\')") // node v16
361+
sprintf(INVALID_BUCKETING_ID, 'BUCKETER', null, "Cannot read property 'length' of null"), // node v14
362+
sprintf(INVALID_BUCKETING_ID, 'BUCKETER', null, "Cannot read properties of null (reading \'length\')") // node v16
362363
]).contain(response.message);
363364
});
364365
});

lib/core/bucketer/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ import {
2828
} from '../../shared_types';
2929

3030
import {
31-
ERROR_MESSAGES,
3231
LOG_LEVEL,
3332
LOG_MESSAGES,
3433
} from '../../utils/enums';
34+
import { INVALID_BUCKETING_ID, INVALID_GROUP_ID } from '../../error_messages';
3535

3636
const HASH_SEED = 1;
3737
const MAX_HASH_VALUE = Math.pow(2, 32);
@@ -63,7 +63,7 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse
6363
if (groupId) {
6464
const group = bucketerParams.groupIdMap[groupId];
6565
if (!group) {
66-
throw new Error(sprintf(ERROR_MESSAGES.INVALID_GROUP_ID, MODULE_NAME, groupId));
66+
throw new Error(sprintf(INVALID_GROUP_ID, MODULE_NAME, groupId));
6767
}
6868
if (group.policy === RANDOM_POLICY) {
6969
const bucketedExperimentId = bucketUserIntoExperiment(
@@ -235,7 +235,7 @@ export const _generateBucketValue = function(bucketingKey: string): number {
235235
const ratio = hashValue / MAX_HASH_VALUE;
236236
return Math.floor(ratio * MAX_TRAFFIC_VALUE);
237237
} catch (ex: any) {
238-
throw new Error(sprintf(ERROR_MESSAGES.INVALID_BUCKETING_ID, MODULE_NAME, bucketingKey, ex.message));
238+
throw new Error(sprintf(INVALID_BUCKETING_ID, MODULE_NAME, bucketingKey, ex.message));
239239
}
240240
};
241241

lib/core/decision_service/index.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
AUDIENCE_EVALUATION_TYPES,
2323
CONTROL_ATTRIBUTES,
2424
DECISION_SOURCES,
25-
ERROR_MESSAGES,
2625
LOG_LEVEL,
2726
LOG_MESSAGES,
2827
} from '../../utils/enums';
@@ -54,6 +53,16 @@ import {
5453
UserProfileService,
5554
Variation,
5655
} from '../../shared_types';
56+
import {
57+
IMPROPERLY_FORMATTED_EXPERIMENT,
58+
INVALID_ROLLOUT_ID,
59+
INVALID_USER_ID,
60+
INVALID_VARIATION_KEY,
61+
NO_VARIATION_FOR_EXPERIMENT_KEY,
62+
USER_NOT_IN_FORCED_VARIATION,
63+
USER_PROFILE_LOOKUP_ERROR,
64+
USER_PROFILE_SAVE_ERROR,
65+
} from '../../error_messages';
5766

5867
export const MODULE_NAME = 'DECISION_SERVICE';
5968

@@ -524,7 +533,7 @@ export class DecisionService {
524533
} catch (ex: any) {
525534
this.logger.log(
526535
LOG_LEVEL.ERROR,
527-
ERROR_MESSAGES.USER_PROFILE_LOOKUP_ERROR,
536+
USER_PROFILE_LOOKUP_ERROR,
528537
MODULE_NAME,
529538
userId,
530539
ex.message,
@@ -579,7 +588,7 @@ export class DecisionService {
579588
userId,
580589
);
581590
} catch (ex: any) {
582-
this.logger.log(LOG_LEVEL.ERROR, ERROR_MESSAGES.USER_PROFILE_SAVE_ERROR, MODULE_NAME, userId, ex.message);
591+
this.logger.log(LOG_LEVEL.ERROR, USER_PROFILE_SAVE_ERROR, MODULE_NAME, userId, ex.message);
583592
}
584593
}
585594

@@ -760,12 +769,12 @@ export class DecisionService {
760769
if (!rollout) {
761770
this.logger.log(
762771
LOG_LEVEL.ERROR,
763-
ERROR_MESSAGES.INVALID_ROLLOUT_ID,
772+
INVALID_ROLLOUT_ID,
764773
MODULE_NAME,
765774
feature.rolloutId,
766775
feature.key,
767776
);
768-
decideReasons.push([ERROR_MESSAGES.INVALID_ROLLOUT_ID, MODULE_NAME, feature.rolloutId, feature.key]);
777+
decideReasons.push([INVALID_ROLLOUT_ID, MODULE_NAME, feature.rolloutId, feature.key]);
769778
decisionObj = {
770779
experiment: null,
771780
variation: null,
@@ -961,7 +970,7 @@ export class DecisionService {
961970
*/
962971
removeForcedVariation(userId: string, experimentId: string, experimentKey: string): void {
963972
if (!userId) {
964-
throw new Error(sprintf(ERROR_MESSAGES.INVALID_USER_ID, MODULE_NAME));
973+
throw new Error(sprintf(INVALID_USER_ID, MODULE_NAME));
965974
}
966975

967976
if (this.forcedVariationMap.hasOwnProperty(userId)) {
@@ -974,7 +983,7 @@ export class DecisionService {
974983
userId,
975984
);
976985
} else {
977-
throw new Error(sprintf(ERROR_MESSAGES.USER_NOT_IN_FORCED_VARIATION, MODULE_NAME, userId));
986+
throw new Error(sprintf(USER_NOT_IN_FORCED_VARIATION, MODULE_NAME, userId));
978987
}
979988
}
980989

@@ -1041,12 +1050,12 @@ export class DecisionService {
10411050
// catching improperly formatted experiments
10421051
this.logger.log(
10431052
LOG_LEVEL.ERROR,
1044-
ERROR_MESSAGES.IMPROPERLY_FORMATTED_EXPERIMENT,
1053+
IMPROPERLY_FORMATTED_EXPERIMENT,
10451054
MODULE_NAME,
10461055
experimentKey,
10471056
);
10481057
decideReasons.push([
1049-
ERROR_MESSAGES.IMPROPERLY_FORMATTED_EXPERIMENT,
1058+
IMPROPERLY_FORMATTED_EXPERIMENT,
10501059
MODULE_NAME,
10511060
experimentKey,
10521061
]);
@@ -1130,7 +1139,7 @@ export class DecisionService {
11301139
variationKey: string | null
11311140
): boolean {
11321141
if (variationKey != null && !stringValidator.validate(variationKey)) {
1133-
this.logger.log(LOG_LEVEL.ERROR, ERROR_MESSAGES.INVALID_VARIATION_KEY, MODULE_NAME);
1142+
this.logger.log(LOG_LEVEL.ERROR, INVALID_VARIATION_KEY, MODULE_NAME);
11341143
return false;
11351144
}
11361145

@@ -1143,7 +1152,7 @@ export class DecisionService {
11431152
// catching improperly formatted experiments
11441153
this.logger.log(
11451154
LOG_LEVEL.ERROR,
1146-
ERROR_MESSAGES.IMPROPERLY_FORMATTED_EXPERIMENT,
1155+
IMPROPERLY_FORMATTED_EXPERIMENT,
11471156
MODULE_NAME,
11481157
experimentKey,
11491158
);
@@ -1170,7 +1179,7 @@ export class DecisionService {
11701179
if (!variationId) {
11711180
this.logger.log(
11721181
LOG_LEVEL.ERROR,
1173-
ERROR_MESSAGES.NO_VARIATION_FOR_EXPERIMENT_KEY,
1182+
NO_VARIATION_FOR_EXPERIMENT_KEY,
11741183
MODULE_NAME,
11751184
variationKey,
11761185
experimentKey,

lib/error_messages.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
export const BROWSER_ODP_MANAGER_INITIALIZATION_FAILED = '%s: Error initializing Browser ODP Manager.';
2+
export const CONDITION_EVALUATOR_ERROR = '%s: Error evaluating audience condition of type %s: %s';
3+
export const DATAFILE_AND_SDK_KEY_MISSING = '%s: You must provide at least one of sdkKey or datafile. Cannot start Optimizely';
4+
export const EXPERIMENT_KEY_NOT_IN_DATAFILE = '%s: Experiment key %s is not in datafile.';
5+
export const FEATURE_NOT_IN_DATAFILE = '%s: Feature key %s is not in datafile.';
6+
export const FETCH_SEGMENTS_FAILED_NETWORK_ERROR = '%s: Audience segments fetch failed. (network error)';
7+
export const FETCH_SEGMENTS_FAILED_DECODE_ERROR = '%s: Audience segments fetch failed. (decode error)';
8+
export const IMPROPERLY_FORMATTED_EXPERIMENT = '%s: Experiment key %s is improperly formatted.';
9+
export const INVALID_ATTRIBUTES = '%s: Provided attributes are in an invalid format.';
10+
export const INVALID_BUCKETING_ID = '%s: Unable to generate hash for bucketing ID %s: %s';
11+
export const INVALID_DATAFILE = '%s: Datafile is invalid - property %s: %s';
12+
export const INVALID_DATAFILE_MALFORMED = '%s: Datafile is invalid because it is malformed.';
13+
export const INVALID_CONFIG = '%s: Provided Optimizely config is in an invalid format.';
14+
export const INVALID_JSON = '%s: JSON object is not valid.';
15+
export const INVALID_ERROR_HANDLER = '%s: Provided "errorHandler" is in an invalid format.';
16+
export const INVALID_EVENT_DISPATCHER = '%s: Provided "eventDispatcher" is in an invalid format.';
17+
export const INVALID_EVENT_TAGS = '%s: Provided event tags are in an invalid format.';
18+
export const INVALID_EXPERIMENT_KEY = '%s: Experiment key %s is not in datafile. It is either invalid, paused, or archived.';
19+
export const INVALID_EXPERIMENT_ID = '%s: Experiment ID %s is not in datafile.';
20+
export const INVALID_GROUP_ID = '%s: Group ID %s is not in datafile.';
21+
export const INVALID_LOGGER = '%s: Provided "logger" is in an invalid format.';
22+
export const INVALID_ROLLOUT_ID = '%s: Invalid rollout ID %s attached to feature %s';
23+
export const INVALID_USER_ID = '%s: Provided user ID is in an invalid format.';
24+
export const INVALID_USER_PROFILE_SERVICE = '%s: Provided user profile service instance is in an invalid format: %s.';
25+
export const LOCAL_STORAGE_DOES_NOT_EXIST = 'Error accessing window localStorage.';
26+
export const MISSING_INTEGRATION_KEY = '%s: Integration key missing from datafile. All integrations should include a key.';
27+
export const NO_DATAFILE_SPECIFIED = '%s: No datafile specified. Cannot start optimizely.';
28+
export const NO_JSON_PROVIDED = '%s: No JSON object to validate against schema.';
29+
export const NO_EVENT_PROCESSOR = 'No event processor is provided';
30+
export const NO_VARIATION_FOR_EXPERIMENT_KEY = '%s: No variation key %s defined in datafile for experiment %s.';
31+
export const ODP_CONFIG_NOT_AVAILABLE = '%s: ODP is not integrated to the project.';
32+
export const ODP_EVENT_FAILED = 'ODP event send failed.';
33+
export const ODP_FETCH_QUALIFIED_SEGMENTS_SEGMENTS_MANAGER_MISSING =
34+
'%s: ODP unable to fetch qualified segments (Segments Manager not initialized).';
35+
export const ODP_IDENTIFY_FAILED_EVENT_MANAGER_MISSING = '%s: ODP identify event %s is not dispatched (Event Manager not instantiated).';
36+
export const ODP_INITIALIZATION_FAILED = '%s: ODP failed to initialize.';
37+
export const ODP_INVALID_DATA = '%s: ODP data is not valid';
38+
export const ODP_EVENT_FAILED_ODP_MANAGER_MISSING = '%s: ODP Event failed to send. (ODP Manager not initialized).';
39+
export const ODP_FETCH_QUALIFIED_SEGMENTS_FAILED_ODP_MANAGER_MISSING =
40+
'%s: ODP failed to Fetch Qualified Segments. (ODP Manager not initialized).';
41+
export const ODP_IDENTIFY_USER_FAILED_ODP_MANAGER_MISSING = '%s: ODP failed to Identify User. (ODP Manager not initialized).';
42+
export const ODP_IDENTIFY_USER_FAILED_USER_CONTEXT_INITIALIZATION =
43+
'%s: ODP failed to Identify User. (Failed during User Context Initialization).';
44+
export const ODP_MANAGER_UPDATE_SETTINGS_FAILED_EVENT_MANAGER_MISSING = '%s: ODP Manager failed to update OdpConfig settings for internal event manager. (Event Manager not initialized).';
45+
export const ODP_MANAGER_UPDATE_SETTINGS_FAILED_SEGMENTS_MANAGER_MISSING = '%s: ODP Manager failed to update OdpConfig settings for internal segments manager. (Segments Manager not initialized).';
46+
export const ODP_NOT_ENABLED = 'ODP is not enabled';
47+
export const ODP_NOT_INTEGRATED = '%s: ODP is not integrated';
48+
export const ODP_SEND_EVENT_FAILED_EVENT_MANAGER_MISSING = '%s: ODP send event %s was not dispatched (Event Manager not instantiated).';
49+
export const ODP_SEND_EVENT_FAILED_UID_MISSING = '%s: ODP send event %s was not dispatched (No valid user identifier provided).';
50+
export const ODP_SEND_EVENT_FAILED_VUID_MISSING = '%s: ODP send event %s was not dispatched (Unable to fetch VUID).';
51+
export const ODP_VUID_INITIALIZATION_FAILED = '%s: ODP VUID initialization failed.';
52+
export const ODP_VUID_REGISTRATION_FAILED = '%s: ODP VUID failed to be registered.';
53+
export const ODP_VUID_REGISTRATION_FAILED_EVENT_MANAGER_MISSING = '%s: ODP register vuid failed. (Event Manager not instantiated).';
54+
export const UNDEFINED_ATTRIBUTE = '%s: Provided attribute: %s has an undefined value.';
55+
export const UNRECOGNIZED_ATTRIBUTE = '%s: Unrecognized attribute %s provided. Pruning before sending event to Optimizely.';
56+
export const UNABLE_TO_CAST_VALUE = '%s: Unable to cast value %s to type %s, returning null.';
57+
export const USER_NOT_IN_FORCED_VARIATION = '%s: User %s is not in the forced variation map. Cannot remove their forced variation.';
58+
export const USER_PROFILE_LOOKUP_ERROR = '%s: Error while looking up user profile for user ID "%s": %s.';
59+
export const USER_PROFILE_SAVE_ERROR = '%s: Error while saving user profile for user ID "%s": %s.';
60+
export const VARIABLE_KEY_NOT_IN_DATAFILE = '%s: Variable with key "%s" associated with feature with key "%s" is not in datafile.';
61+
export const VARIATION_ID_NOT_IN_DATAFILE = '%s: No variation ID %s defined in datafile for experiment %s.';
62+
export const VARIATION_ID_NOT_IN_DATAFILE_NO_EXPERIMENT = '%s: Variation ID %s is not in the datafile.';
63+
export const INVALID_INPUT_FORMAT = '%s: Provided %s is in an invalid format.';
64+
export const INVALID_DATAFILE_VERSION = '%s: This version of the JavaScript SDK does not support the given datafile version: %s';
65+
export const INVALID_VARIATION_KEY = '%s: Provided variation key is in an invalid format.';

lib/index.browser.tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
import logging, { getLogger } from './modules/logging/logger';
1817

1918
import { assert } from 'chai';
@@ -33,6 +32,7 @@ import { BrowserOdpEventApiManager } from './odp/event_manager/event_api_manager
3332
import { OdpEvent } from './odp/event_manager/odp_event';
3433
import { getMockProjectConfigManager } from './tests/mock/mock_project_config_manager';
3534
import { createProjectConfig } from './project_config/project_config';
35+
import { ODP_EVENT_FAILED_ODP_MANAGER_MISSING } from './error_messages';
3636

3737

3838
class MockLocalStorage {
@@ -1109,7 +1109,7 @@ describe('javascript-sdk (Browser)', function() {
11091109

11101110
sinon.assert.calledWith(
11111111
logger.error,
1112-
optimizelyFactory.enums.ERROR_MESSAGES.ODP_EVENT_FAILED_ODP_MANAGER_MISSING
1112+
ODP_EVENT_FAILED_ODP_MANAGER_MISSING
11131113
);
11141114
});
11151115

lib/odp/event_manager/odp_event_manager.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
import { LogHandler, LogLevel } from '../../modules/logging';
1818

1919
import { uuid } from '../../utils/fns';
20-
import { ERROR_MESSAGES, ODP_USER_KEY, ODP_DEFAULT_EVENT_TYPE, ODP_EVENT_ACTION } from '../../utils/enums';
20+
import { ODP_USER_KEY, ODP_DEFAULT_EVENT_TYPE, ODP_EVENT_ACTION } from '../../utils/enums';
2121

2222
import { OdpEvent } from './odp_event';
2323
import { OdpConfig } from '../odp_config';
2424
import { IOdpEventApiManager } from './odp_event_api_manager';
2525
import { invalidOdpDataFound } from '../odp_utils';
2626
import { IUserAgentParser } from '../ua_parser/user_agent_parser';
2727
import { scheduleMicrotask } from '../../utils/microtask';
28+
import { ODP_CONFIG_NOT_AVAILABLE, ODP_SEND_EVENT_FAILED_UID_MISSING } from '../../error_messages';
2829

2930
const MAX_RETRIES = 3;
3031

@@ -223,7 +224,7 @@ export abstract class OdpEventManager implements IOdpEventManager {
223224
*/
224225
start(): void {
225226
if (!this.odpConfig) {
226-
this.logger.log(LogLevel.ERROR, ERROR_MESSAGES.ODP_CONFIG_NOT_AVAILABLE);
227+
this.logger.log(LogLevel.ERROR, ODP_CONFIG_NOT_AVAILABLE);
227228
return;
228229
}
229230

@@ -267,7 +268,7 @@ export abstract class OdpEventManager implements IOdpEventManager {
267268
identifyUser(userId?: string, vuid?: string): void {
268269
const identifiers = new Map<string, string>();
269270
if (!userId && !vuid) {
270-
this.logger.log(LogLevel.ERROR, ERROR_MESSAGES.ODP_SEND_EVENT_FAILED_UID_MISSING);
271+
this.logger.log(LogLevel.ERROR, ODP_SEND_EVENT_FAILED_UID_MISSING);
271272
return;
272273
}
273274

lib/odp/odp_manager.browser.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616

1717
import {
1818
CLIENT_VERSION,
19-
ERROR_MESSAGES,
2019
JAVASCRIPT_CLIENT_ENGINE,
2120
ODP_USER_KEY,
2221
REQUEST_TIMEOUT_ODP_SEGMENTS_MS,
2322
REQUEST_TIMEOUT_ODP_EVENTS_MS,
24-
LOG_MESSAGES,
2523
} from '../utils/enums';
26-
import { getLogger, LogHandler, LogLevel } from '../modules/logging';
24+
import { getLogger, LogHandler } from '../modules/logging';
2725

2826
import { BrowserRequestHandler } from '../utils/http_request_handler/browser_request_handler';
2927

@@ -40,6 +38,7 @@ import { BrowserOdpEventManager } from './event_manager/event_manager.browser';
4038
import { IOdpSegmentManager, OdpSegmentManager } from './segment_manager/odp_segment_manager';
4139
import { OdpSegmentApiManager } from './segment_manager/odp_segment_api_manager';
4240
import { OdpConfig, OdpIntegrationConfig } from './odp_config';
41+
import { ODP_SEND_EVENT_FAILED_VUID_MISSING } from '../error_messages';
4342

4443
interface BrowserOdpManagerConfig {
4544
clientEngine?: string,
@@ -185,7 +184,7 @@ export class BrowserOdpManager extends OdpManager {
185184
if (this.vuid) {
186185
identifiersWithVuid.set(ODP_USER_KEY.VUID, this.vuid);
187186
} else {
188-
throw new Error(ERROR_MESSAGES.ODP_SEND_EVENT_FAILED_VUID_MISSING);
187+
throw new Error(ODP_SEND_EVENT_FAILED_VUID_MISSING);
189188
}
190189
}
191190

0 commit comments

Comments
 (0)