diff --git a/ioctl/doc/doc.go b/ioctl/doc/doc.go index d887ccf4bc..37573ca7ae 100644 --- a/ioctl/doc/doc.go +++ b/ioctl/doc/doc.go @@ -16,12 +16,12 @@ import ( // GenMarkdownTreeCustom is the the same as GenMarkdownTree, but // with custom filePrepender and linkHandler. func GenMarkdownTreeCustom(c *cobra.Command, dir string, name string, path string, filePrepender func(string) string, - linkHandler func(*cobra.Command, string) string) error { + linkHandler func(*cobra.Command, string) string) (err error) { for _, child := range c.Commands() { if !child.IsAvailableCommand() || child.IsAdditionalHelpTopicCommand() { continue } - if err := GenMarkdownTreeCustom(child, dir, name, path, filePrepender, linkHandler); err != nil { + if err = GenMarkdownTreeCustom(child, dir, name, path, filePrepender, linkHandler); err != nil { return err } } @@ -32,19 +32,21 @@ func GenMarkdownTreeCustom(c *cobra.Command, dir string, name string, path strin filename = filepath.Join(path, "README.md") } - f, err := os.Create(filepath.Clean(filename)) + var f *os.File + f, err = os.Create(filepath.Clean(filename)) if err != nil { return err } - defer f.Close() - - if _, err := io.WriteString(f, filePrepender(filename)); err != nil { + defer func() { + err = f.Close() + }() + if _, err = io.WriteString(f, filePrepender(filename)); err != nil { return err } - if err := GenMarkdownCustom(c, f, linkHandler); err != nil { + if err = GenMarkdownCustom(c, f, linkHandler); err != nil { return err } - return nil + return err } // GenMarkdownCustom creates custom markdown output. diff --git a/pkg/recovery/recovery.go b/pkg/recovery/recovery.go index 6d82330dbb..b9c012e494 100644 --- a/pkg/recovery/recovery.go +++ b/pkg/recovery/recovery.go @@ -84,9 +84,15 @@ func writeHeapProfile(path string) { log.S().Errorf("crashlog: open heap profile error: %v", err) return } - defer f.Close() + defer func() { + if err = f.Close(); err != nil { + log.S().Errorf("crashlog: close heap profile error: %v", err) + return + } + }() if err := pprof.WriteHeapProfile(f); err != nil { log.S().Errorf("crashlog: write heap profile error: %v", err) + return } }