@@ -20,6 +20,7 @@ package client
20
20
import (
21
21
"errors"
22
22
"fmt"
23
+ "reflect"
23
24
"runtime/debug"
24
25
"strconv"
25
26
@@ -57,7 +58,7 @@ func (o *OptimizelyClient) Activate(experimentKey string, userContext entities.U
57
58
default :
58
59
err = errors .New ("unexpected error" )
59
60
}
60
- errorMessage := fmt .Sprintf ("optimizely SDK is panicking with the error:" )
61
+ errorMessage := fmt .Sprintf ("Activate call, optimizely SDK is panicking with the error:" )
61
62
logger .Error (errorMessage , err )
62
63
logger .Debug (string (debug .Stack ()))
63
64
}
@@ -69,7 +70,7 @@ func (o *OptimizelyClient) Activate(experimentKey string, userContext entities.U
69
70
return result , err
70
71
}
71
72
72
- if experimentDecision .Variation != nil {
73
+ if experimentDecision .Variation != nil && decisionContext . Experiment != nil {
73
74
// send an impression event
74
75
result = experimentDecision .Variation .Key
75
76
impressionEvent := event .CreateImpressionUserEvent (decisionContext .ProjectConfig , * decisionContext .Experiment , * experimentDecision .Variation , userContext )
@@ -93,7 +94,7 @@ func (o *OptimizelyClient) IsFeatureEnabled(featureKey string, userContext entit
93
94
default :
94
95
err = errors .New ("unexpected error" )
95
96
}
96
- errorMessage := fmt .Sprintf ("optimizely SDK is panicking with the error:" )
97
+ errorMessage := fmt .Sprintf ("IsFeatureEnabled call, optimizely SDK is panicking with the error:" )
97
98
logger .Error (errorMessage , err )
98
99
logger .Debug (string (debug .Stack ()))
99
100
}
@@ -117,7 +118,7 @@ func (o *OptimizelyClient) IsFeatureEnabled(featureKey string, userContext entit
117
118
logger .Info (fmt .Sprintf (`Feature "%s" is not enabled for user "%s".` , featureKey , userContext .ID ))
118
119
}
119
120
120
- if featureDecision .Source == decision .FeatureTest {
121
+ if featureDecision .Source == decision .FeatureTest && featureDecision . Variation != nil {
121
122
// send impression event for feature tests
122
123
impressionEvent := event .CreateImpressionUserEvent (decisionContext .ProjectConfig , featureDecision .Experiment , * featureDecision .Variation , userContext )
123
124
o .EventProcessor .ProcessEvent (impressionEvent )
@@ -139,7 +140,7 @@ func (o *OptimizelyClient) GetEnabledFeatures(userContext entities.UserContext)
139
140
default :
140
141
err = errors .New ("unexpected error" )
141
142
}
142
- errorMessage := fmt .Sprintf ("optimizely SDK is panicking with the error:" )
143
+ errorMessage := fmt .Sprintf ("GetEnabledFeatures call, optimizely SDK is panicking with the error:" )
143
144
logger .Error (errorMessage , err )
144
145
logger .Debug (string (debug .Stack ()))
145
146
}
@@ -280,7 +281,7 @@ func (o *OptimizelyClient) GetVariation(experimentKey string, userContext entiti
280
281
default :
281
282
err = errors .New ("unexpected error" )
282
283
}
283
- errorMessage := fmt .Sprintf ("optimizely SDK is panicking with the error:" )
284
+ errorMessage := fmt .Sprintf ("GetVariation call, optimizely SDK is panicking with the error:" )
284
285
logger .Error (errorMessage , err )
285
286
logger .Debug (string (debug .Stack ()))
286
287
}
@@ -312,7 +313,7 @@ func (o *OptimizelyClient) Track(eventKey string, userContext entities.UserConte
312
313
default :
313
314
err = errors .New ("unexpected error" )
314
315
}
315
- errorMessage := fmt .Sprintf ("optimizely SDK is panicking with the error:" )
316
+ errorMessage := fmt .Sprintf ("Track call, optimizely SDK is panicking with the error:" )
316
317
logger .Error (errorMessage , err )
317
318
logger .Debug (string (debug .Stack ()))
318
319
}
@@ -355,7 +356,7 @@ func (o *OptimizelyClient) getFeatureDecision(featureKey, variableKey string, us
355
356
default :
356
357
err = errors .New ("unexpected error" )
357
358
}
358
- errorMessage := fmt .Sprintf ("optimizely SDK is panicking with the error:" )
359
+ errorMessage := fmt .Sprintf ("getFeatureDecision call, optimizely SDK is panicking with the error:" )
359
360
logger .Error (errorMessage , err )
360
361
logger .Debug (string (debug .Stack ()))
361
362
}
@@ -477,6 +478,9 @@ func (o *OptimizelyClient) RemoveOnTrack(id int) error {
477
478
478
479
func (o * OptimizelyClient ) getProjectConfig () (projectConfig config.ProjectConfig , err error ) {
479
480
481
+ if isNil (o .ConfigManager ) {
482
+ return nil , errors .New ("project config manager is not initialized" )
483
+ }
480
484
projectConfig , err = o .ConfigManager .GetConfig ()
481
485
if err != nil {
482
486
return nil , err
@@ -496,3 +500,7 @@ func (o *OptimizelyClient) GetOptimizelyConfig() (optimizelyConfig *config.Optim
496
500
func (o * OptimizelyClient ) Close () {
497
501
o .execGroup .TerminateAndWait ()
498
502
}
503
+
504
+ func isNil (v interface {}) bool {
505
+ return v == nil || (reflect .ValueOf (v ).Kind () == reflect .Ptr && reflect .ValueOf (v ).IsNil ())
506
+ }
0 commit comments