From ef999a039c9c1c6a857456434d031ec27a1d1a78 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 8 Nov 2020 14:07:26 -0800 Subject: [PATCH] Perhaps better error stacks for backups/archives; ref #2418 --- server/archiver.go | 15 +++++---------- server/backup.go | 13 ++++++------- server/filesystem/compress.go | 2 +- server/filesystem/path.go | 2 +- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/server/archiver.go b/server/archiver.go index 951c6c9..99492de 100644 --- a/server/archiver.go +++ b/server/archiver.go @@ -41,7 +41,7 @@ func (a *Archiver) Exists() bool { func (a *Archiver) Stat() (*filesystem.Stat, error) { s, err := os.Stat(a.Path()) if err != nil { - return nil, errors.WithStackIf(err) + return nil, errors.WithStack(err) } return &filesystem.Stat{ @@ -58,7 +58,7 @@ func (a *Archiver) Archive() error { var files []string fileInfo, err := ioutil.ReadDir(path) if err != nil { - return err + return errors.WithStack(err) } for _, file := range fileInfo { @@ -72,7 +72,6 @@ func (a *Archiver) Archive() error { // and not the actual file in this listing. if file.Mode()&os.ModeSymlink != 0 { f, err = a.Server.Filesystem().SafePath(filepath.Join(path, file.Name())) - if err != nil { return err } @@ -95,21 +94,17 @@ func (a *Archiver) DeleteIfExists() error { return nil } - return err - } - - if err := os.Remove(a.Path()); err != nil { return errors.WithStackIf(err) } - return nil + return errors.WrapIf(os.Remove(a.Path()), "archiver: failed to delete archive from system") } // Checksum computes a SHA256 checksum of the server's archive. func (a *Archiver) Checksum() (string, error) { file, err := os.Open(a.Path()) if err != nil { - return "", err + return "", errors.WithStack(err) } defer file.Close() @@ -117,7 +112,7 @@ func (a *Archiver) Checksum() (string, error) { buf := make([]byte, 1024*4) if _, err := io.CopyBuffer(hash, file, buf); err != nil { - return "", err + return "", errors.WithStack(err) } return hex.EncodeToString(hash.Sum(nil)), nil diff --git a/server/backup.go b/server/backup.go index c50003e..ec8a379 100644 --- a/server/backup.go +++ b/server/backup.go @@ -13,8 +13,7 @@ import ( // Notifies the panel of a backup's state and returns an error if one is encountered // while performing this action. func (s *Server) notifyPanelOfBackup(uuid string, ad *backup.ArchiveDetails, successful bool) error { - r := api.New() - err := r.SendBackupStatus(uuid, ad.ToRequest(successful)) + err := api.New().SendBackupStatus(uuid, ad.ToRequest(successful)) if err != nil { if !api.IsRequestError(err) { s.Log().WithFields(log.Fields{ @@ -22,7 +21,7 @@ func (s *Server) notifyPanelOfBackup(uuid string, ad *backup.ArchiveDetails, suc "error": err, }).Error("failed to notify panel of backup status due to wings error") - return err + return errors.WithStackIf(err) } return errors.New(err.Error()) @@ -38,7 +37,7 @@ func (s *Server) getServerwideIgnoredFiles() ([]string, error) { f, err := os.Open(path.Join(s.Filesystem().Path(), ".pteroignore")) if err != nil { if !os.IsNotExist(err) { - return nil, err + return nil, errors.WithStack(err) } } else { scanner := bufio.NewScanner(f) @@ -50,7 +49,7 @@ func (s *Server) getServerwideIgnoredFiles() ([]string, error) { } if err := scanner.Err(); err != nil { - return nil, err + return nil, errors.WithStack(err) } } @@ -100,7 +99,7 @@ func (s *Server) Backup(b backup.BackupInterface) error { "file_size": 0, }) - return errors.WrapIf(err, "error while generating server backup") + return errors.WrapIf(err, "backup: error while generating server backup") } // Try to notify the panel about the status of this backup. If for some reason this request @@ -108,7 +107,7 @@ func (s *Server) Backup(b backup.BackupInterface) error { if notifyError := s.notifyPanelOfBackup(b.Identifier(), ad, true); notifyError != nil { b.Remove() - return notifyError + return errors.WithStackIf(err) } // Emit an event over the socket so we can update the backup in realtime on diff --git a/server/filesystem/compress.go b/server/filesystem/compress.go index c83e4d3..31c33df 100644 --- a/server/filesystem/compress.go +++ b/server/filesystem/compress.go @@ -27,7 +27,7 @@ func (fs *Filesystem) GetIncludedFiles(dir string, ignored []string) (*backup.In i, err := ignore.CompileIgnoreLines(ignored...) if err != nil { - return nil, err + return nil, errors.WithStack(err) } // Walk through all of the files and directories on a server. This callback only returns diff --git a/server/filesystem/path.go b/server/filesystem/path.go index 8b3cd44..de8e572 100644 --- a/server/filesystem/path.go +++ b/server/filesystem/path.go @@ -138,5 +138,5 @@ func (fs *Filesystem) ParallelSafePath(paths []string) ([]string, error) { } // Block until all of the routines finish and have returned a value. - return cleaned, g.Wait() + return cleaned, errors.WithStackIf(g.Wait()) }