Skip to content

Commit 42bcf1c

Browse files
committed
Minor nil pointer bug translation fix
1 parent 55301b1 commit 42bcf1c

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

reverse.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,22 @@ func MapValueToLocation(mapToSearch map[string]interface{}, location, value stri
3030
} else {
3131
// Continue searching
3232
newMap := make(map[string]interface{})
33-
for k, v := range mapValue.(map[string]interface{}) {
34-
newMap[k] = v
33+
if val, ok := mapValue.(map[string]interface{}); ok {
34+
for k, v := range val {
35+
newMap[k] = v
36+
}
37+
} else if val, ok := mapValue.([]interface{}); ok {
38+
log.Printf("[ERROR] Schemaless handling []interface{} with arbitary values. This MAY not work. MapValue: %#v", mapValue)
39+
for i, v := range val {
40+
if mapValue, ok := v.(map[string]interface{}); ok {
41+
newMap[fmt.Sprintf("#%d", i)] = mapValue
42+
} else {
43+
newMap[fmt.Sprintf("#%d", i)] = v
44+
}
45+
}
46+
} else {
47+
log.Printf("[ERROR] Schemaless handling unknown type %#v. Value: %#v", reflect.TypeOf(mapValue).String(), value)
48+
continue
3549
}
3650

3751
mapToSearch[key] = MapValueToLocation(newMap, strings.Join(locationParts[1:], "."), value)

translate.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -814,34 +814,26 @@ func Translate(ctx context.Context, inputStandard string, inputValue []byte, inp
814814
keyTokenFile := fmt.Sprintf("%s%s-%x", filenamePrefix, inputStandard, md5.Sum([]byte(keyToken)))
815815
err = SaveParsedInput(keyTokenFile, returnJson, shuffleConfig)
816816
if err != nil {
817-
log.Printf("[ERROR] Schemaless: Error in SaveParsedInput for file %s: '%v'", keyTokenFile, err)
818-
return []byte{}, err
817+
log.Printf("[WARNING] Schemaless: Error in SaveParsedInput for file %s: '%v'", keyTokenFile, err)
818+
return inputValue, nil
819819
}
820820

821821
// Check if the keyToken is already in cache and use that translation layer
822822
//log.Printf("\n\n[DEBUG] Schemaless: Getting existing structure for keyToken: '%s'\n\n", keyTokenFile)
823823
inputStructure, err := GetExistingStructure(keyTokenFile, shuffleConfig)
824824

825-
826-
//log.Printf("[DEBUG] Schemaless: Found existing structure: %v", string(inputStructure))
827825
fixedOutput := FixTranslationStructure(string(inputStructure))
828-
829-
//log.Printf("[DEBUG] Schemaless: Fixed output: %v", fixedOutput)
830-
831826
inputStructure = []byte(fixedOutput)
832-
833827
if err == nil {
834828
//log.Printf("\n\n[DEBUG] Schemaless: Found existing structure for keyToken: '%s': %#v\n\n", keyTokenFile, string(inputStructure))
835829
} else {
836830
// Check if the standard exists at all
837831
standardFormat, err := GetStandard(inputStandard, shuffleConfig)
838832
if err != nil {
839-
log.Printf("[ERROR] Schemaless: Error in GetStandard for standard %#v: %v", inputStandard, err)
840-
return []byte{}, err
833+
log.Printf("[WARNING] Schemaless: Problem in GetStandard for standard %#v: %v", inputStandard, err)
834+
return inputValue, nil
841835
}
842836

843-
//log.Printf("\n\nFOUND STANDARD (%s): %v\n\n", inputStandard, string(standardFormat))
844-
845837
trimmedStandard := strings.TrimSpace(string(standardFormat))
846838
if !skipSubstandard && len(trimmedStandard) > 2 && strings.Contains(trimmedStandard, ".json") && strings.HasPrefix(trimmedStandard, "[") && strings.HasSuffix(trimmedStandard, "]") {
847839

0 commit comments

Comments
 (0)