-
Notifications
You must be signed in to change notification settings - Fork 19
[FSSDK-11649] Fix FSC failed tests for CMAB #411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
54101be
6c419fe
5dcef46
1ba0e3c
c0ac22c
c8b55e0
8305a90
45d51cf
1e92f00
7bcfe8a
d2181fb
a76accc
2c913ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/**************************************************************************** | ||
* Copyright 2025, Optimizely, Inc. and contributors * | ||
* * | ||
* Licensed under the Apache License, Version 2.0 (the "License"); * | ||
* you may not use this file except in compliance with the License. * | ||
* You may obtain a copy of the License at * | ||
* * | ||
* http://www.apache.org/licenses/LICENSE-2.0 * | ||
* * | ||
* Unless required by applicable law or agreed to in writing, software * | ||
* distributed under the License is distributed on an "AS IS" BASIS, * | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
* See the License for the specific language governing permissions and * | ||
* limitations under the License. * | ||
***************************************************************************/ | ||
|
||
// Package cmab to define cmab errors// | ||
package cmab | ||
|
||
// CmabFetchFailed is the error message format for CMAB fetch failures | ||
// Format required for FSC test compatibility - capitalized and with period | ||
const CmabFetchFailed = "Failed to fetch CMAB data for experiment %s." //nolint:ST1005 // Required exact format for FSC test compatibility |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
package decision | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/optimizely/go-sdk/v2/pkg/decide" | ||
"github.com/optimizely/go-sdk/v2/pkg/entities" | ||
"github.com/optimizely/go-sdk/v2/pkg/logging" | ||
|
@@ -51,6 +53,21 @@ func (f CompositeFeatureService) GetDecision(decisionContext FeatureDecisionCont | |
reasons.Append(decisionReasons) | ||
if err != nil { | ||
f.logger.Debug(err.Error()) | ||
// Check if this is a CMAB error - if so, stop the loop and return empty decision | ||
if strings.Contains(err.Error(), "Failed to fetch CMAB data") { | ||
// Add the CMAB error to reasons before returning - use AddError for critical failures | ||
reasons.AddError(err.Error()) | ||
return FeatureDecision{}, reasons, nil // Return empty decision for CMAB errors | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should return the error here |
||
} | ||
} | ||
|
||
// Also check for CMAB errors in decision reasons (when err is nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if there was an error, the featureDecisionService.GetDecision() call must return an error, there should be no implicit errors. Please remove this if block |
||
if decisionReasons != nil { | ||
for _, reason := range decisionReasons.ToReport() { | ||
if strings.Contains(reason, "Failed to fetch CMAB data") { | ||
return FeatureDecision{}, reasons, nil | ||
} | ||
} | ||
} | ||
|
||
if featureDecision.Variation != nil && err == nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,9 +159,12 @@ func (s *ExperimentCmabService) GetDecision(decisionContext ExperimentDecisionCo | |
// Get CMAB decision | ||
cmabDecision, err := s.cmabService.GetDecision(projectConfig, userContext, experiment.ID, options) | ||
if err != nil { | ||
message := fmt.Sprintf("Failed to get CMAB decision: %v", err) | ||
decisionReasons.AddInfo(message) | ||
return decision, decisionReasons, fmt.Errorf("failed to get CMAB decision: %w", err) | ||
// Add CMAB error to decision reasons | ||
errorMessage := fmt.Sprintf(cmab.CmabFetchFailed, experiment.Key) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this message processing is also being done in cmab_service. I guess we can do this here and keep the code in cmab_service unchanged? |
||
decisionReasons.AddInfo(errorMessage) | ||
|
||
// Use same format for Go error - FSC compatibility takes precedence | ||
return decision, decisionReasons, errors.New(errorMessage) //nolint:ST1005 // Required exact format for FSC test compatibility | ||
} | ||
|
||
// Find variation by ID | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is an error from the featureDecisonfeatureDecisionService.GetDecision() call, we should just return the error from here. The caller of this method should deal with the error.