lib/versioner: Improve error messages (fixes #7354) (#7357)

This commit is contained in:
Simon Frei
2021-02-12 20:30:51 +01:00
committed by GitHub
parent 5e9c7bc022
commit 7e4e2f3720
7 changed files with 58 additions and 13 deletions
+7 -3
View File
@@ -9,6 +9,7 @@ package versioner
import (
"context"
"errors"
"fmt"
"os"
"os/exec"
"runtime"
@@ -64,12 +65,12 @@ func (v external) Archive(filePath string) error {
l.Debugln("archiving", filePath)
if v.command == "" {
return errors.New("Versioner: command is empty, please enter a valid command")
return errors.New("command is empty, please enter a valid command")
}
words, err := shellquote.Split(v.command)
if err != nil {
return errors.New("Versioner: command is invalid: " + err.Error())
return fmt.Errorf("command is invalid: %w", err)
}
context := map[string]string{
@@ -99,6 +100,9 @@ func (v external) Archive(filePath string) error {
combinedOutput, err := cmd.CombinedOutput()
l.Debugln("external command output:", string(combinedOutput))
if err != nil {
if eerr, ok := err.(*exec.ExitError); ok && len(eerr.Stderr) > 0 {
return fmt.Errorf("%v: %v", err, string(eerr.Stderr))
}
return err
}
@@ -106,7 +110,7 @@ func (v external) Archive(filePath string) error {
if _, err = v.filesystem.Lstat(filePath); fs.IsNotExist(err) {
return nil
}
return errors.New("Versioner: file was not removed by external script")
return errors.New("file was not removed by external script")
}
func (v external) GetVersions() (map[string][]FileVersion, error) {