{"record":{"id":"da3aeb869f280d40","repo":"alibaba/open-code-review","slug":"unmarshal-default-system-rules-w","errorCode":null,"errorMessage":"unmarshal default system rules: %w","messagePattern":"unmarshal default system rules: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/config/rules/system_rules.go","lineNumber":100,"sourceCode":"\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)\n\t}\n\tcontent, err := rulesFS.ReadFile(\"rule_docs/\" + rule.DefaultRule)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read default rule file %q: %w\", rule.DefaultRule, err)\n\t}\n\trule.DefaultRule = strings.TrimRight(string(content), \"\\n\")\n\tfor i := range rule.PathRules {\n\t\tcontent, err := rulesFS.ReadFile(\"rule_docs/\" + rule.PathRules[i].Rule)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"read rule file %q for pattern %q: %w\", rule.PathRules[i].Rule, rule.PathRules[i].Pattern, err)\n\t\t}\n\t\trule.PathRules[i].Rule = strings.TrimRight(string(content), \"\\n\")\n\t}\n\treturn &rule, nil\n}\n\n// loadObjCRule reads the embedded Objective-C rule doc used by the \".m\"\n// content sniff. It is not referenced from system_rules.json's path_rule_map,","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/config/rules/system_rules.go#L82-L118","documentation":"LoadDefault unmarshals the embedded system_rules.json into SystemRule (using the custom UnmarshalJSON). This error wraps json.Unmarshal's failure: the embedded JSON is syntactically invalid or violates the custom decoder's expectations (e.g. path_rule_map value not a string).","triggerScenarios":"The embedded system_rules.json contains invalid JSON — trailing commas, unquoted keys, bad escapes, or a path_rule_map entry whose value is not a string.","commonSituations":"A bad edit to the checked-in system_rules.json got committed; an automated script rewrote the file; merge conflict markers left in the JSON.","solutions":["Validate internal/config/rules/system_rules.json with jq or a JSON linter and fix the syntax error at the reported offset","Check for leftover merge-conflict markers (<<<<<<<) or trailing commas","Run the package tests (make test) after fixing to confirm LoadDefault succeeds"],"exampleFix":"// before (invalid)\n{\"default_rule\": \"default.md\", \"path_rule_map\": {\"**/*.go\": \"go.md\",}}\n// after\n{\"default_rule\": \"default.md\", \"path_rule_map\": {\"**/*.go\": \"go.md\"}}","handlingStrategy":"validation","validationCode":"var pretty map[string]any\nif err := json.Unmarshal(systemRulesJSON, &pretty); err != nil {\n\tvar se *json.SyntaxError\n\tif errors.As(err, &se) {\n\t\tline := strings.Count(string(systemRulesJSON[:se.Offset]), \"\\n\") + 1\n\t\treturn fmt.Errorf(\"system_rules.json invalid at line %d: %v\", line, err)\n\t}\n\treturn err\n}","typeGuard":null,"tryCatchPattern":"rule, err := rules.LoadDefault()\nif err != nil {\n\tif strings.Contains(err.Error(), \"unmarshal default system rules\") {\n\t\tlog.Fatalf(\"embedded system_rules.json is invalid JSON: %v — this is a build bug, report/fix the file\", err)\n\t}\n\treturn err\n}","preventionTips":["Validate system_rules.json with jq in CI on every change","Reject merge-conflict markers and trailing commas via a pre-commit hook","Run make test after editing any embedded JSON"],"tags":["json","embed","unmarshal"],"backgroundTag":"json-parse-error","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}