{"record":{"id":"6e55c1ee4b7899a3","repo":"alibaba/open-code-review","slug":"read-path-rule-map-value-for-q-w","errorCode":null,"errorMessage":"read path_rule_map value for %q: %w","messagePattern":"read path_rule_map value for %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/rules/system_rules.go","lineNumber":82,"sourceCode":"\t\treturn fmt.Errorf(\"expected '{' in path_rule_map: %w\", err)\n\t}\n\tif t != json.Delim('{') {\n\t\treturn fmt.Errorf(\"expected '{' in path_rule_map, got %v\", t)\n\t}\n\tfor dec.More() {\n\t\t// Read key\n\t\tkeyTok, err := dec.Token()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"read path_rule_map key: %w\", err)\n\t\t}\n\t\tkey, ok := keyTok.(string)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"expected string key in path_rule_map, got %T\", keyTok)\n\t\t}\n\t\t// Read value\n\t\tvar value string\n\t\tif err := dec.Decode(&value); err != nil {\n\t\t\treturn fmt.Errorf(\"read path_rule_map value for %q: %w\", key, err)\n\t\t}\n\t\tr.PathRules = append(r.PathRules, PathRule{Pattern: key, Rule: value})\n\t}\n\treturn nil\n}\n\n//go:embed system_rules.json rule_docs/*\nvar rulesFS embed.FS\n\n// LoadDefault parses the embedded system_rules.json and resolves rule file references.\nfunc LoadDefault() (*SystemRule, error) {\n\tdata, err := rulesFS.ReadFile(\"system_rules.json\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read embedded system_rules.json: %w\", err)\n\t}\n\tvar rule SystemRule\n\tif err := json.Unmarshal(data, &rule); err != nil {\n\t\treturn nil, fmt.Errorf(\"unmarshal default system rules: %w\", err)","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/config/rules/system_rules.go#L64-L100","documentation":"SystemRule.UnmarshalJSON streams path_rule_map with a json.Decoder and decodes each value into a plain string. This error wraps the json.Decoder.Decode failure, meaning the value for the given key is not a JSON string (e.g. an object, array, number, bool, or malformed JSON). It exists so the offending pattern name is preserved in the message.","triggerScenarios":"json.Unmarshal into SystemRule where any value inside path_rule_map is not a JSON string, or the map is truncated/malformed after a key. Example: {\"path_rule_map\":{\"**/*.go\":{}}} or {\"path_rule_map\":{\"**/*.go\":}}.","commonSituations":"Hand-edited or generated rule config where someone put an object/array as the rule value instead of a rule file reference string; a template expansion that left an empty or nested value; encoding corruption after a key.","solutions":["Open the rule JSON (embedded system_rules.json or the project/global rule file being parsed) and make every path_rule_map value a plain JSON string naming a rule doc file","Validate the JSON with a linter (jq) before shipping: jq '.path_rule_map' rule.json — every value must be a string","If a value needs structured data, change the schema and UnmarshalJSON, do not nest it under path_rule_map"],"exampleFix":"// before\n{\"path_rule_map\": {\"**/*.go\": {\"rule\": \"golang.md\"}}}\n// after\n{\"path_rule_map\": {\"**/*.go\": \"golang.md\"}}","handlingStrategy":"validation","validationCode":"raw, err := os.ReadFile(cfgPath)\nif err != nil { return err }\nvar probe struct {\n\tPathRuleMap map[string]json.RawMessage `json:\"path_rule_map\"`\n}\nif err := json.Unmarshal(raw, &probe); err != nil { return err }\nfor k, v := range probe.PathRuleMap {\n\tvar s string\n\tif err := json.Unmarshal(v, &s); err != nil {\n\t\treturn fmt.Errorf(\"path_rule_map[%q] must be a string, got: %s\", k, v)\n\t}\n}","typeGuard":"func isStringJSON(b json.RawMessage) bool {\n\tvar s string\n\treturn json.Unmarshal(b, &s) == nil\n}","tryCatchPattern":"var rule rules.SystemRule\nif err := json.Unmarshal(data, &rule); err != nil {\n\tvar sint *json.SyntaxError\n\tvar ute *json.UnmarshalTypeError\n\tswitch {\n\tcase errors.As(err, &sint): log.Fatalf(\"invalid JSON at offset %d: %v\", sint.Offset, err)\n\tcase errors.As(err, &ute): log.Fatalf(\"wrong type at %s: %v\", ute.Field, err)\n\tdefault: log.Fatalf(\"path_rule_map value error: %v\", err)\n\t}\n}","preventionTips":["Keep path_rule_map values as flat strings referencing rule doc filenames","Run jq (or a JSON schema check) over rule configs in CI before they ship","Never hand-write nested JSON inside path_rule_map values"],"tags":["json","config","unmarshal"],"backgroundTag":"schema-validation-failed","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}