Skip to content

Commit 9cb3ccf

Browse files
Handle null conditions and excluded fields in IRBSegment parsing
1 parent 3979c59 commit 9cb3ccf

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

src/dtos/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,11 @@ export interface IRBSegment {
208208
name: string,
209209
changeNumber: number,
210210
status: 'ACTIVE' | 'ARCHIVED',
211-
conditions?: ISplitCondition[],
211+
conditions?: ISplitCondition[] | null,
212212
excluded?: {
213213
keys?: string[] | null,
214214
segments?: IExcludedSegment[] | null
215-
}
215+
} | null
216216
}
217217

218218
export interface ISplit {

src/sync/polling/updaters/splitChangesUpdater.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function checkAllSegmentsExist(segments: ISegmentsCacheBase): Promise<boolean> {
3131
* Exported for testing purposes.
3232
*/
3333
export function parseSegments(ruleEntity: ISplit | IRBSegment, matcherType: typeof IN_SEGMENT | typeof IN_RULE_BASED_SEGMENT = IN_SEGMENT): Set<string> {
34-
const { conditions = [], excluded } = ruleEntity as IRBSegment;
34+
const { conditions, excluded } = ruleEntity as IRBSegment;
3535

3636
const segments = new Set<string>();
3737
if (excluded && excluded.segments) {
@@ -42,12 +42,14 @@ export function parseSegments(ruleEntity: ISplit | IRBSegment, matcherType: type
4242
});
4343
}
4444

45-
for (let i = 0; i < conditions.length; i++) {
46-
const matchers = conditions[i].matcherGroup.matchers;
45+
if (conditions) {
46+
for (let i = 0; i < conditions.length; i++) {
47+
const matchers = conditions[i].matcherGroup.matchers;
4748

48-
matchers.forEach(matcher => {
49-
if (matcher.matcherType === matcherType) segments.add(matcher.userDefinedSegmentMatcherData.segmentName);
50-
});
49+
matchers.forEach(matcher => {
50+
if (matcher.matcherType === matcherType) segments.add(matcher.userDefinedSegmentMatcherData.segmentName);
51+
});
52+
}
5153
}
5254

5355
return segments;

0 commit comments

Comments
 (0)