{"record":{"id":"aecac9c14f556135","repo":"alibaba/open-code-review","slug":"read-path-rule-map-key-w","errorCode":null,"errorMessage":"read path_rule_map key: %w","messagePattern":"read path_rule_map key: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/rules/system_rules.go","lineNumber":73,"sourceCode":"\tif !ok || len(mapData) == 0 || string(mapData) == \"null\" {\n\t\treturn nil\n\t}\n\n\t// Parse ordered keys using a streaming decoder.\n\tdec := json.NewDecoder(strings.NewReader(string(mapData)))\n\t// Read opening '{'\n\tt, err := dec.Token()\n\tif err != nil {\n\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","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/config/rules/system_rules.go#L55-L91","documentation":"While iterating path_rule_map keys with the streaming decoder, dec.Token() failed mid-object — the map started with '{' but the stream broke before the next key could be read (unexpected EOF or invalid character). This wraps the decoder's underlying error, so a malformed/tuncated JSON object surfaces here.","triggerScenarios":"path_rule_map is a JSON object that is syntactically truncated or corrupted after the opening brace — missing closing '}', an unquoted key, or invalid characters between entries — encountered during SystemRule unmarshalling.","commonSituations":"Configs cut off by failed writes or size-limited传输; hand-edited files with an unquoted key or a missing comma between members; template rendering that dropped the tail of the file.","solutions":["Validate the file with 'jq .' or any JSON parser to locate the syntax error","Ensure every key in path_rule_map is a double-quoted string and members are comma-separated","Restore the file from a known-good version or regenerate it","Check for encoding issues (BOM, control characters) that break the decoder"],"exampleFix":"// before (unquoted key, no comma)\n{\"*.go\": \"golang.md\" \"*.py\": python.md}\n// after\n{\"*.go\": \"golang.md\", \"*.py\": \"python.md\"}","handlingStrategy":"validation","validationCode":"func preflightRulesJSON(data []byte) error {\n    if err := json.Valid(data); !err { return errors.New(\"file is not valid JSON\") }\n    var probe map[string]json.RawMessage\n    if err := json.Unmarshal(data, &probe); err != nil { return err }\n    m, ok := probe[\"path_rule_map\"]\n    if !ok || string(m) == \"null\" { return nil }\n    return json.Unmarshal(m, &map[string]string{})\n}","typeGuard":null,"tryCatchPattern":"if err := json.Unmarshal(data, &rule); err != nil {\n    if strings.Contains(err.Error(), \"read path_rule_map key\") {\n        // decoder broke mid-object: report the decoder cause\n        log.Errorf(\"path_rule_map truncated or malformed: %v\", err)\n    }\n    return err\n}","preventionTips":["Ensure atomic config writes (write temp file, then rename) to avoid truncation","Quote every key and separate members with commas","Run 'jq .' as a pre-commit/CI gate on rules files","Check for BOM/control characters when configs travel through editors or templates"],"tags":["config","json-parsing","rules"],"backgroundTag":"invalid-json-config","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}