{"record":{"id":"2e0d32a7b11e9dd0","repo":"shadow1ng/fscan","slug":"failed-to-load-en-yaml-v","errorCode":null,"errorMessage":"failed to load en.yaml: %v","messagePattern":"failed to load en\\.yaml: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"common/i18n/i18n.go","lineNumber":41,"sourceCode":")\n\nvar (\n\tbundle    *i18n.Bundle\n\tlocalizer *i18n.Localizer\n\tlang      = DefaultLanguage\n\tmu        sync.RWMutex\n)\n\nfunc init() {\n\tbundle = i18n.NewBundle(language.Chinese)\n\tbundle.RegisterUnmarshalFunc(\"yaml\", yaml.Unmarshal)\n\n\t// 从embed加载翻译文件\n\tif _, err := bundle.LoadMessageFileFS(localeFS, \"locales/zh.yaml\"); err != nil {\n\t\tpanic(fmt.Sprintf(\"failed to load zh.yaml: %v\", err))\n\t}\n\tif _, err := bundle.LoadMessageFileFS(localeFS, \"locales/en.yaml\"); err != nil {\n\t\tpanic(fmt.Sprintf(\"failed to load en.yaml: %v\", err))\n\t}\n\n\tlocalizer = i18n.NewLocalizer(bundle, lang, FallbackLanguage)\n}\n\n// SetLanguage 设置当前语言\nfunc SetLanguage(l string) {\n\tmu.Lock()\n\tdefer mu.Unlock()\n\tlang = l\n\tlocalizer = i18n.NewLocalizer(bundle, lang, FallbackLanguage)\n}\n\n// GetLanguage returns the currently configured language.\nfunc GetLanguage() string {\n\tmu.RLock()\n\tdefer mu.RUnlock()\n\treturn lang","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/common/i18n/i18n.go#L23-L59","documentation":"Same init-time loading as zh.yaml but for locales/en.yaml, the fallback English translation file. A missing or malformed en.yaml makes the i18n bundle incomplete and the package panics deliberately at startup rather than serving broken translations.","triggerScenarios":"locales/en.yaml not embedded (missing file, embed directive mismatch), or en.yaml failing yaml.Unmarshal due to syntax errors.","commonSituations":"Hand-edited en.yaml with invalid YAML, file renamed during refactoring, or a merge that dropped the file while keeping the embed directive.","solutions":["Confirm common/i18n/locales/en.yaml exists and is covered by the //go:embed pattern","Fix any YAML syntax errors in en.yaml","Rebuild so the embedded FS reflects the on-disk file"],"exampleFix":"// before\nlocales:\n  - en.yaml missing\n// after\n// common/i18n/locales/en.yaml restored:\n// hello:\n//   other: \"Hello\"","handlingStrategy":"try-catch","validationCode":"if _, err := localeFS.ReadFile(\"locales/en.yaml\"); err != nil {\n    // en.yaml missing or embed pattern mismatch; fix before build\n}","typeGuard":null,"tryCatchPattern":"// init-time panic: cannot be caught; catch via CI test\ntest: func TestLocalesEmbedded(t *testing.T) {\n    if _, err := localeFS.ReadFile(\"locales/en.yaml\"); err != nil {\n        t.Fatalf(\"en.yaml missing from embed: %v\", err)\n    }\n}","preventionTips":["Lint all YAML in locales/ in CI","Never rename locale files without updating the embed directive","Add a test that NewLocalizer succeeds with both languages"],"tags":["i18n","yaml","embed","startup"],"backgroundTag":"module-init-failed","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}