Perhaps better error stacks for backups/archives; ref #2418

This commit is contained in:
Dane Everitt 2020-11-08 14:07:26 -08:00
parent be9d1a3986
commit ef999a039c
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
4 changed files with 13 additions and 19 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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())
}