{"record":{"id":"128b45ffb77b16f8","repo":"Tencent/WeKnora","slug":"failed-to-marshal-condition-at-index-d-w","errorCode":null,"errorMessage":"failed to marshal condition at index %d: %w","messagePattern":"failed to marshal condition at index (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/repository/retriever/milvus/filter.go","lineNumber":274,"sourceCode":"\t\treturn err\n\t}\n\n\tc.Field = aux.Field\n\tc.Operator = strings.ToLower(aux.Operator)\n\n\t// Handle logical operators (and/or) - Value should be []*UniversalFilterCondition\n\tif c.Operator == operatorAnd || c.Operator == operatorOr {\n\t\t// Value can be an array of conditions\n\t\tvalueSlice, ok := aux.Value.([]any)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"logical operator %s requires an array of conditions\", c.Operator)\n\t\t}\n\n\t\tconditions := make([]*universalFilterCondition, 0, len(valueSlice))\n\t\tfor i, v := range valueSlice {\n\t\t\tcondBytes, err := json.Marshal(v)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to marshal condition at index %d: %w\", i, err)\n\t\t\t}\n\n\t\t\tvar cond universalFilterCondition\n\t\t\tif err := json.Unmarshal(condBytes, &cond); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to unmarshal condition at index %d: %w\", i, err)\n\t\t\t}\n\t\t\tconditions = append(conditions, &cond)\n\t\t}\n\t\tc.Value = conditions\n\t} else {\n\t\tc.Value = aux.Value\n\t}\n\n\treturn nil\n}\n\n// MarshalJSON implements custom JSON marshaling for UniversalFilterCondition.\nfunc (c *universalFilterCondition) MarshalJSON() ([]byte, error) {","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/repository/retriever/milvus/filter.go#L256-L292","documentation":"During UnmarshalJSON of an AND/OR condition, each array element is re-marshaled to JSON bytes before being decoded into universalFilterCondition. This error wraps a json.Marshal failure on the element at the given index (%w preserves the underlying error).","triggerScenarios":"An array element that cannot be marshaled back to JSON — practically rare since elements came from unmarshaled JSON, but possible with channels/funcs/cycles injected programmatically into the raw value map.","commonSituations":"Custom JSON.Unmarshaler interactions or test fixtures building aux.Value maps containing unsupported Go types; corrupt intermediate values from upstream decoding hooks.","solutions":["Inspect the wrapped error and index to find the offending element","Ensure each array element is a plain JSON-compatible object (map[string]any)","Avoid injecting non-JSON-serializable Go values into the decoded structure"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"var f Filter\nif err := json.Unmarshal(data, &f); err != nil {\n  var idxErr *fmt.WrapError\n  if strings.Contains(err.Error(), \"failed to marshal condition at index\") {\n    return nil, fmt.Errorf(\"unserializable element in logical value: %w\", err)\n  }\n  return nil, err\n}","preventionTips":["Keep logical value arrays as plain JSON objects","Avoid injecting Go-native non-JSON types into decoded structures","Test unmarshal paths with real JSON fixtures"],"tags":["milvus","json","marshal"],"backgroundTag":"json-marshal-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}