{"record":{"id":"b91362aac1ebfead","repo":"shadow1ng/fscan","slug":"failed-to-load-zh-yaml-v","errorCode":null,"errorMessage":"failed to load zh.yaml: %v","messagePattern":"failed to load zh\\.yaml: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"common/i18n/i18n.go","lineNumber":38,"sourceCode":"const (\n\tDefaultLanguage  = LangZH\n\tFallbackLanguage = LangEN\n)\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 {","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/common/i18n/i18n.go#L20-L56","documentation":"The i18n package's init function embeds locale files (localeFS) and loads locales/zh.yaml into an go-i18n bundle at startup. If the embedded file is missing, unreadable, or not valid YAML, the package panics with this message because translations cannot work at all. It runs at program start, so it crashes the whole binary.","triggerScenarios":"locales/zh.yaml absent from the embedded FS (embed pattern not matching, file deleted/renamed), or zh.yaml containing YAML syntax errors that yaml.Unmarshal rejects.","commonSituations":"Moving/renaming the locales directory without updating the //go:embed directive, editing zh.yaml by hand and introducing bad YAML (tabs, unquoted colons), or build tags excluding the file.","solutions":["Verify common/i18n/locales/zh.yaml exists and matches the //go:embed pattern","Validate zh.yaml syntax with a YAML linter/parser and fix parse errors","Rebuild the binary so the embed FS picks up the current file contents","Check the embed directive includes the locales directory recursively"],"exampleFix":"// before\n//go:embed locales\nvar localeFS embed.FS // zh.yaml accidentally deleted\n// after\n// restore locales/zh.yaml with valid content:\n// hello:\n//   other: \"你好\"","handlingStrategy":"try-catch","validationCode":"if _, err := localeFS.ReadFile(\"locales/zh.yaml\"); err != nil {\n    // embed pattern broken or file missing; fix before depending on i18n\n}","typeGuard":null,"tryCatchPattern":"// init-time panic: cannot be caught at call time; guard by adding a test\ntest: func TestLocalesEmbedded(t *testing.T) {\n    if _, err := localeFS.ReadFile(\"locales/zh.yaml\"); err != nil {\n        t.Fatalf(\"zh.yaml missing from embed: %v\", err)\n    }\n}","preventionTips":["Keep //go:embed directives covering the whole locales directory","Run YAML linting in CI for files under locales/","Add a startup/embed test validating both locale files parse"],"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"}