{"record":{"id":"1bdd9211791e1d2c","repo":"alibaba/open-code-review","slug":"read-embedded-system-rules-json-w","errorCode":null,"errorMessage":"read embedded system_rules.json: %w","messagePattern":"read embedded system_rules\\.json: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/config/rules/system_rules.go","lineNumber":96,"sourceCode":"\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)\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","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/config/rules/system_rules.go#L78-L114","documentation":"LoadDefault reads the embedded system_rules.json from the go:embed filesystem. This error wraps the embed.FS.ReadFile failure. Because the file is embedded at compile time, this should be impossible in a normal build and almost always indicates a broken embed directive, missing file, or a nonstandard build.","triggerScenarios":"rulesFS.ReadFile(\"system_rules.json\") fails: the //go:embed pattern was edited, the file was renamed/deleted, or the package is built in an environment that stripped embedded files.","commonSituations":"After refactoring the package directory, the file moved but the embed pattern wasn't updated; build tooling that post-processes/strip binaries; custom build systems bypassing go:embed.","solutions":["Verify internal/config/rules/system_rules.json exists and the //go:embed directive lists it (go:embed system_rules.json rule_docs/*)","Run go build ./... to regenerate/validate embedding; check the file is not in .gitignore and present in the module","If the error persists in a custom build, rebuild with the standard Go toolchain so embed files are packed"],"exampleFix":"// before\n//go:embed rule_docs/*\nvar rulesFS embed.FS\n// after\n//go:embed system_rules.json rule_docs/*\nvar rulesFS embed.FS","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"rule, err := rules.LoadDefault()\nif err != nil {\n\tif strings.Contains(err.Error(), \"read embedded system_rules.json\") {\n\t\tlog.Fatalf(\"broken build: embedded assets missing (%v) — rebuild with the standard Go toolchain\", err)\n\t}\n\treturn fmt.Errorf(\"load default rules: %w\", err)\n}","preventionTips":["Never edit the //go:embed directive without running go build ./... immediately after","Keep system_rules.json inside internal/config/rules/ next to the embed declaration","Add a package test that calls LoadDefault so CI catches embed breakage at build time"],"tags":["embed","build","go"],"backgroundTag":"embedded-asset-missing","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}