{"record":{"id":"b0bf6acb1a59930c","repo":"flipped-aurora/gin-vue-admin","slug":"filepath-s-b0bf6a","errorCode":null,"errorMessage":"[filepath:%s]注入失败!","messagePattern":"\\[filepath:(.+?)\\]注入失败!","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/ast/interfaces_base.go","lineNumber":57,"sourceCode":"\treturn nil\n}\n\nfunc (a *Base) Format(filename string, writer io.Writer, file *ast.File) error {\n\tfileSet := a.FileSet\n\tif fileSet == nil {\n\t\tfileSet = token.NewFileSet()\n\t}\n\tif writer == nil {\n\t\topen, err := os.OpenFile(filename, os.O_WRONLY|os.O_TRUNC, 0666)\n\t\tdefer open.Close()\n\t\tif err != nil {\n\t\t\treturn errors.Wrapf(err, \"[filepath:%s]打开文件失败!\", filename)\n\t\t}\n\t\twriter = open\n\t}\n\terr := format.Node(writer, fileSet, file)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"[filepath:%s]注入失败!\", filename)\n\t}\n\treturn nil\n}\n\n// RelativePath 绝对路径转相对路径\nfunc (a *Base) RelativePath(filePath string) string {\n\tserver := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server)\n\thasServer := strings.Index(filePath, server)\n\tif hasServer != -1 {\n\t\tfilePath = strings.TrimPrefix(filePath, server)\n\t\tkeys := strings.Split(filePath, string(filepath.Separator))\n\t\tfilePath = path.Join(keys...)\n\t}\n\treturn filePath\n}\n\n// AbsolutePath 相对路径转绝对路径\nfunc (a *Base) AbsolutePath(filePath string) string {","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/utils/ast/interfaces_base.go#L39-L75","documentation":"After successfully opening the file, Base.Format writes the AST via format.Node; if the printer or underlying writer fails (disk full, closed file, broken pipe) the error is wrapped with '注入失败!'. It signals the AST-to-source write-back stage failed, not the parsing or opening stages.","triggerScenarios":"Calling Base.Format when format.Node returns an error — typically the file descriptor became invalid, the disk is full, or an AST node passed in is invalid for printing; also when the deferred-open pattern yields a writer whose write later fails.","commonSituations":"Disk quota exceeded on CI runners; writing to a container layer that is read-only; piping output somewhere that closes early; extremely rare invalid AST from manual ast.NewFile construction.","solutions":["Check disk space/quota (df -h) and free space or fix quota","Verify the output volume/filesystem is writable","Confirm the *ast.File passed to Format came from Parse and was not hand-constructed with invalid nodes","Retry the generation after addressing the I/O condition"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if free, _ := sysDiskFree(path); free < 10<<20 { return errors.New(\"insufficient disk space for codegen\") }","typeGuard":null,"tryCatchPattern":"if err := base.Format(filename, file); err != nil { if !strings.Contains(err.Error(), \"注入失败\") == false { /* handle writeback failure: retry or restore from backup */ } ; return err }","preventionTips":["Keep source backups before injection so a failed write-back can be rolled back","Monitor disk quota on CI machines","Only feed ASTs produced by Parse into Format","Handle I/O errors idempotently: rerunning codegen should be safe"],"tags":["go","ast","codegen","io"],"backgroundTag":"ast-writeback-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}