Skip to content

Commit 07b5dcf

Browse files
committed
return error if unmarshalling while checking empty json
1 parent d70306d commit 07b5dcf

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

pkg/pipeline/util/CiCdUtil.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ func GetWorkflowCacheConfig(WorkflowCacheConfig common.WorkflowCacheConfigType,
2424

2525
// in oss, only WorkflowCacheConfigInherit is supported
2626
func GetWorkflowCacheConfigWithBackwardCompatibility(WorkflowCacheConfig common.WorkflowCacheConfigType, WorkflowCacheConfigEnv string, globalValue bool, oldGlobalValue bool) bean.WorkflowCacheConfig {
27-
if util.IsEmptyJSONForJsonString(WorkflowCacheConfigEnv) {
27+
isEmptyJson, _ := util.IsEmptyJSONForJsonString(WorkflowCacheConfigEnv)
28+
//TODO: error handling in next phase
29+
if isEmptyJson {
2830
//this means new global flag is not configured
2931
return bean.WorkflowCacheConfig{
3032
Type: common.WorkflowCacheConfigInherit,

util/JsonHelper.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ package util
33
import "encoding/json"
44

55
// IsEmptyJSON checks if a given string represents an empty JSON object
6-
func IsEmptyJSONForJsonString(jsonStr string) bool {
6+
func IsEmptyJSONForJsonString(jsonStr string) (bool, error) {
77
var data interface{}
88
err := json.Unmarshal([]byte(jsonStr), &data)
99
if err != nil {
1010
// If unmarshaling fails, it's not valid JSON
11-
return false
11+
return false, err
1212
}
1313

1414
// Check if data is an empty map
1515
if obj, ok := data.(map[string]interface{}); ok {
16-
return len(obj) == 0
16+
return len(obj) == 0, nil
1717
}
1818

1919
// If not a JSON object, return false
20-
return false
20+
return false, nil
2121
}

0 commit comments

Comments
 (0)