flipped-aurora/gin-vue-admin · error

[filepath:%s]生成失败!

Error message

[filepath:%s]生成失败!

What it means

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.

Source

Thrown at server/service/system/auto_code_package.go:79

		for key, value := range creates { // key 为 模版绝对路径
			var files *template.Template
			files, err = template.New(filepath.Base(key)).Funcs(autocode.GetTemplateFuncMap()).ParseFiles(key)
			if err != nil {
				return errors.Wrapf(err, "[filepath:%s]读取模版文件失败!", key)
			}
			err = os.MkdirAll(filepath.Dir(value), os.ModePerm)
			if err != nil {
				return errors.Wrapf(err, "[filepath:%s]创建文件夹失败!", value)
			}
			var file *os.File
			file, err = os.Create(value)
			if err != nil {
				return errors.Wrapf(err, "[filepath:%s]创建文件夹失败!", value)
			}
			err = files.Execute(file, code)
			_ = file.Close()
			if err != nil {
				return errors.Wrapf(err, "[filepath:%s]生成失败!", value)
			}
			fmt.Printf("[template:%s][filepath:%s]生成成功!\n", key, value)
		}
		for key, value := range asts {
			keys := strings.Split(key, "=>")
			if len(keys) == 2 {
				switch keys[1] {
				case ast.TypePluginInitializeV2, ast.TypePackageApiEnter, ast.TypePackageRouterEnter, ast.TypePackageServiceEnter:
					file, _ := value.Parse("", nil)
					if file != nil {
						err = value.Injection(file)
						if err != nil {
							return err
						}
						err = value.Format("", nil, file)
						if err != nil {
							return err
						}

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Read the wrapped inner error to identify the failing template expression (field or function name)
  2. Fix the template so referenced fields exist on the AutoCode struct or add the missing func to autocode.GetTemplateFuncMap
  3. Revert recently customized templates in the template directory to stock versions to confirm the cause
  4. If caused by an upgrade, regenerate templates matching the current gin-vue-admin codegen model

Example fix

// before: template references missing field
{{ .NonExistentField }}
// after: guard with a field that exists or use a safe default
{{ if .HasFlag }}{{ .Flag }}{{ else }}default{{ end }}
Defensive patterns

Strategy: try-catch

Try / catch

err = files.Execute(file, code)
_ = file.Close()
if err != nil {
    var tErr template.ExecError
    if errors.As(err, &tErr) {
        log.Printf("template %s failed at %s: %v", files.Name(), tErr.Error(), err)
    }
    return errors.Wrapf(err, "[filepath:%s]生成失败!", value)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/5a00bf8d16e7d990. Report an issue: GitHub.