return exit code 10 if repository does not exist
This commit is contained in:
parent
d76a78aa99
commit
94fdca08c4
32 changed files with 46 additions and 1 deletions
|
@ -41,6 +41,7 @@ EXIT STATUS
|
|||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was a fatal error (no snapshot created).
|
||||
Exit status is 3 if some source data could not be read (incomplete snapshot created).
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
PreRun: func(_ *cobra.Command, _ []string) {
|
||||
|
|
|
@ -23,6 +23,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -37,6 +37,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -36,6 +36,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
|
|
@ -45,6 +45,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -41,6 +41,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -36,6 +36,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -35,6 +35,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -37,6 +37,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -21,6 +21,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -25,6 +25,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -21,6 +21,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -22,6 +22,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -21,6 +21,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -41,6 +41,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -24,6 +24,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -66,6 +66,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -30,6 +30,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -24,6 +24,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -21,6 +21,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -25,6 +25,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -39,6 +39,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -34,6 +34,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -40,6 +40,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -26,6 +26,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -25,6 +25,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -51,6 +51,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -27,6 +27,7 @@ EXIT STATUS
|
|||
|
||||
Exit status is 0 if the command was successful.
|
||||
Exit status is 1 if there was any error.
|
||||
Exit status is 10 if the repository does not exist.
|
||||
Exit status is 11 if the repository is already locked.
|
||||
`,
|
||||
DisableAutoGenTag: true,
|
||||
|
|
|
@ -43,6 +43,10 @@ import (
|
|||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
// ErrNoRepository is used to report if opening a repsitory failed due
|
||||
// to a missing backend storage location or config file
|
||||
var ErrNoRepository = errors.New("repository does not exist")
|
||||
|
||||
var version = "0.16.5-dev (compiled manually)"
|
||||
|
||||
// TimeFormat is the format used for all timestamps printed by restic.
|
||||
|
@ -607,6 +611,9 @@ func innerOpen(ctx context.Context, s string, gopts GlobalOptions, opts options.
|
|||
be, err = factory.Open(ctx, cfg, rt, lim)
|
||||
}
|
||||
|
||||
if errors.Is(err, backend.ErrNoRepository) {
|
||||
return nil, fmt.Errorf("Fatal: %w at %v: %v", ErrNoRepository, location.StripPassword(gopts.backends, s), err)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errors.Fatalf("unable to open repository at %v: %v", location.StripPassword(gopts.backends, s), err)
|
||||
}
|
||||
|
@ -635,6 +642,9 @@ func open(ctx context.Context, s string, gopts GlobalOptions, opts options.Optio
|
|||
|
||||
// check if config is there
|
||||
fi, err := be.Stat(ctx, backend.Handle{Type: restic.ConfigFile})
|
||||
if be.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("Fatal: %w: unable to open config file: %v\nIs there a repository at the following location?\n%v", ErrNoRepository, err, location.StripPassword(gopts.backends, s))
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errors.Fatalf("unable to open config file: %v\nIs there a repository at the following location?\n%v", err, location.StripPassword(gopts.backends, s))
|
||||
}
|
||||
|
|
|
@ -156,6 +156,8 @@ func main() {
|
|||
exitCode = 0
|
||||
case err == ErrInvalidSourceData:
|
||||
exitCode = 3
|
||||
case errors.Is(err, ErrNoRepository):
|
||||
exitCode = 10
|
||||
case restic.IsAlreadyLocked(err):
|
||||
exitCode = 11
|
||||
case errors.Is(err, context.Canceled):
|
||||
|
|
|
@ -100,7 +100,9 @@ func Open(ctx context.Context, cfg Config, rt http.RoundTripper) (backend.Backen
|
|||
}
|
||||
|
||||
bucket, err := client.Bucket(ctx, cfg.Bucket)
|
||||
if err != nil {
|
||||
if b2.IsNotExist(err) {
|
||||
return nil, backend.ErrNoRepository
|
||||
} else if err != nil {
|
||||
return nil, errors.Wrap(err, "Bucket")
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,13 @@ package backend
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"hash"
|
||||
"io"
|
||||
)
|
||||
|
||||
var ErrNoRepository = fmt.Errorf("repository does not exist")
|
||||
|
||||
// Backend is used to store and access data.
|
||||
//
|
||||
// Backend operations that return an error will be retried when a Backend is
|
||||
|
|
Loading…
Reference in a new issue