alibaba/open-code-review · critical
read embedded system_rules.json: %w
Error message
read embedded system_rules.json: %w
What it means
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.
Source
Thrown at internal/config/rules/system_rules.go:96
}
// Read value
var value string
if err := dec.Decode(&value); err != nil {
return fmt.Errorf("read path_rule_map value for %q: %w", key, err)
}
r.PathRules = append(r.PathRules, PathRule{Pattern: key, Rule: value})
}
return nil
}
//go:embed system_rules.json rule_docs/*
var rulesFS embed.FS
// LoadDefault parses the embedded system_rules.json and resolves rule file references.
func LoadDefault() (*SystemRule, error) {
data, err := rulesFS.ReadFile("system_rules.json")
if err != nil {
return nil, fmt.Errorf("read embedded system_rules.json: %w", err)
}
var rule SystemRule
if err := json.Unmarshal(data, &rule); err != nil {
return nil, fmt.Errorf("unmarshal default system rules: %w", err)
}
content, err := rulesFS.ReadFile("rule_docs/" + rule.DefaultRule)
if err != nil {
return nil, fmt.Errorf("read default rule file %q: %w", rule.DefaultRule, err)
}
rule.DefaultRule = strings.TrimRight(string(content), "\n")
for i := range rule.PathRules {
content, err := rulesFS.ReadFile("rule_docs/" + rule.PathRules[i].Rule)
if err != nil {
return nil, fmt.Errorf("read rule file %q for pattern %q: %w", rule.PathRules[i].Rule, rule.PathRules[i].Pattern, err)
}
rule.PathRules[i].Rule = strings.TrimRight(string(content), "\n")
}
return &rule, nilView on GitHub (pinned to 5cf97d0d15)
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
Example fix
// before //go:embed rule_docs/* var rulesFS embed.FS // after //go:embed system_rules.json rule_docs/* var rulesFS embed.FS
Defensive patterns
Strategy: try-catch
Try / catch
rule, err := rules.LoadDefault()
if err != nil {
if strings.Contains(err.Error(), "read embedded system_rules.json") {
log.Fatalf("broken build: embedded assets missing (%v) — rebuild with the standard Go toolchain", err)
}
return fmt.Errorf("load default rules: %w", err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- read objc rule file: %w
- read prompt file %q: %w
- %s: %w
- read embedded task_template.json: %w
- MAIN_TASK: %w
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/1bdd9211791e1d2c.
Report an issue: GitHub.