{"record":{"id":"5a00bf8d16e7d990","repo":"flipped-aurora/gin-vue-admin","slug":"filepath-s-5a00bf","errorCode":null,"errorMessage":"[filepath:%s]生成失败!","messagePattern":"\\[filepath:(.+?)\\]生成失败!","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/auto_code_package.go","lineNumber":79,"sourceCode":"\t\tfor key, value := range creates { // key 为 模版绝对路径\n\t\t\tvar files *template.Template\n\t\t\tfiles, err = template.New(filepath.Base(key)).Funcs(autocode.GetTemplateFuncMap()).ParseFiles(key)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrapf(err, \"[filepath:%s]读取模版文件失败!\", key)\n\t\t\t}\n\t\t\terr = os.MkdirAll(filepath.Dir(value), os.ModePerm)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrapf(err, \"[filepath:%s]创建文件夹失败!\", value)\n\t\t\t}\n\t\t\tvar file *os.File\n\t\t\tfile, err = os.Create(value)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrapf(err, \"[filepath:%s]创建文件夹失败!\", value)\n\t\t\t}\n\t\t\terr = files.Execute(file, code)\n\t\t\t_ = file.Close()\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrapf(err, \"[filepath:%s]生成失败!\", value)\n\t\t\t}\n\t\t\tfmt.Printf(\"[template:%s][filepath:%s]生成成功!\\n\", key, value)\n\t\t}\n\t\tfor key, value := range asts {\n\t\t\tkeys := strings.Split(key, \"=>\")\n\t\t\tif len(keys) == 2 {\n\t\t\t\tswitch keys[1] {\n\t\t\t\tcase ast.TypePluginInitializeV2, ast.TypePackageApiEnter, ast.TypePackageRouterEnter, ast.TypePackageServiceEnter:\n\t\t\t\t\tfile, _ := value.Parse(\"\", nil)\n\t\t\t\t\tif file != nil {\n\t\t\t\t\t\terr = value.Injection(file)\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn err\n\t\t\t\t\t\t}\n\t\t\t\t\t\terr = value.Format(\"\", nil, file)\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn err\n\t\t\t\t\t\t}","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/auto_code_package.go#L61-L97","documentation":"This error occurs after the template file was parsed and the output file created, when template.Execute fails to render the parsed template into the output file. It wraps the template execution error (missing template function, bad field reference, syntax issue in the template) with the destination file path. The file is closed before the check, so no file-descriptor leak occurs, but a partially written output file may remain.","triggerScenarios":"Executing an auto-code template (files.Execute(file, code)) during package Create when the template references a field or function not present on the AutoCode struct, uses an unregistered template func from GetTemplateFuncMap, or the template data has nil pointers/missing map keys.","commonSituations":"Customized or third-party templates referencing fields removed/renamed in a gin-vue-admin version upgrade; typo in {{ .FieldName }}; using a custom func in the template that was never added to the funcs map.","solutions":["Read the wrapped inner error to identify the failing template expression (field or function name)","Fix the template so referenced fields exist on the AutoCode struct or add the missing func to autocode.GetTemplateFuncMap","Revert recently customized templates in the template directory to stock versions to confirm the cause","If caused by an upgrade, regenerate templates matching the current gin-vue-admin codegen model"],"exampleFix":"// before: template references missing field\n{{ .NonExistentField }}\n// after: guard with a field that exists or use a safe default\n{{ if .HasFlag }}{{ .Flag }}{{ else }}default{{ end }}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"err = files.Execute(file, code)\n_ = file.Close()\nif err != nil {\n    var tErr template.ExecError\n    if errors.As(err, &tErr) {\n        log.Printf(\"template %s failed at %s: %v\", files.Name(), tErr.Error(), err)\n    }\n    return errors.Wrapf(err, \"[filepath:%s]生成失败!\", value)\n}","preventionTips":["Keep templates in sync with the AutoCode struct fields after upgrades","Register every function used in templates in GetTemplateFuncMap","Add CI render tests that execute all templates with sample data","Avoid calling methods on possibly-nil pointer fields in templates without guards"],"tags":["template","codegen","go"],"backgroundTag":"template-execution-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}