return exit code 10 if repository does not exist

This commit is contained in:
Michael Eischer 2024-07-10 21:46:26 +02:00
parent d76a78aa99
commit 94fdca08c4
32 changed files with 46 additions and 1 deletions

View file

@ -41,6 +41,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. 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 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 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. Exit status is 11 if the repository is already locked.
`, `,
PreRun: func(_ *cobra.Command, _ []string) { PreRun: func(_ *cobra.Command, _ []string) {

View file

@ -23,6 +23,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -37,6 +37,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -36,6 +36,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {

View file

@ -45,6 +45,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -41,6 +41,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -36,6 +36,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -35,6 +35,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -37,6 +37,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -21,6 +21,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -25,6 +25,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -21,6 +21,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -22,6 +22,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -21,6 +21,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -41,6 +41,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -24,6 +24,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -66,6 +66,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -30,6 +30,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -24,6 +24,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -21,6 +21,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -25,6 +25,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -39,6 +39,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -34,6 +34,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -40,6 +40,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -26,6 +26,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -25,6 +25,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -51,6 +51,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -27,6 +27,7 @@ EXIT STATUS
Exit status is 0 if the command was successful. Exit status is 0 if the command was successful.
Exit status is 1 if there was any error. 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. Exit status is 11 if the repository is already locked.
`, `,
DisableAutoGenTag: true, DisableAutoGenTag: true,

View file

@ -43,6 +43,10 @@ import (
"golang.org/x/term" "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)" var version = "0.16.5-dev (compiled manually)"
// TimeFormat is the format used for all timestamps printed by restic. // 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) 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 { if err != nil {
return nil, errors.Fatalf("unable to open repository at %v: %v", location.StripPassword(gopts.backends, s), err) 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 // check if config is there
fi, err := be.Stat(ctx, backend.Handle{Type: restic.ConfigFile}) 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 { 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)) 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))
} }

View file

@ -156,6 +156,8 @@ func main() {
exitCode = 0 exitCode = 0
case err == ErrInvalidSourceData: case err == ErrInvalidSourceData:
exitCode = 3 exitCode = 3
case errors.Is(err, ErrNoRepository):
exitCode = 10
case restic.IsAlreadyLocked(err): case restic.IsAlreadyLocked(err):
exitCode = 11 exitCode = 11
case errors.Is(err, context.Canceled): case errors.Is(err, context.Canceled):

View file

@ -100,7 +100,9 @@ func Open(ctx context.Context, cfg Config, rt http.RoundTripper) (backend.Backen
} }
bucket, err := client.Bucket(ctx, cfg.Bucket) 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") return nil, errors.Wrap(err, "Bucket")
} }

View file

@ -2,10 +2,13 @@ package backend
import ( import (
"context" "context"
"fmt"
"hash" "hash"
"io" "io"
) )
var ErrNoRepository = fmt.Errorf("repository does not exist")
// Backend is used to store and access data. // Backend is used to store and access data.
// //
// Backend operations that return an error will be retried when a Backend is // Backend operations that return an error will be retried when a Backend is