Merge pull request #623 from restic/fix-622
Improve error messages for open repo
This commit is contained in:
commit
c5763e59d5
2 changed files with 23 additions and 19 deletions
|
@ -296,16 +296,18 @@ func open(s string) (restic.Backend, error) {
|
|||
debug.Log("open", "parsing location %v", s)
|
||||
loc, err := location.Parse(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Fatalf("parsing repository location failed: %v", err)
|
||||
}
|
||||
|
||||
var be restic.Backend
|
||||
|
||||
switch loc.Scheme {
|
||||
case "local":
|
||||
debug.Log("open", "opening local repository at %#v", loc.Config)
|
||||
return local.Open(loc.Config.(string))
|
||||
be, err = local.Open(loc.Config.(string))
|
||||
case "sftp":
|
||||
debug.Log("open", "opening sftp repository at %#v", loc.Config)
|
||||
return sftp.OpenWithConfig(loc.Config.(sftp.Config))
|
||||
be, err = sftp.OpenWithConfig(loc.Config.(sftp.Config))
|
||||
case "s3":
|
||||
cfg := loc.Config.(s3.Config)
|
||||
if cfg.KeyID == "" {
|
||||
|
@ -317,13 +319,18 @@ func open(s string) (restic.Backend, error) {
|
|||
}
|
||||
|
||||
debug.Log("open", "opening s3 repository at %#v", cfg)
|
||||
return s3.Open(cfg)
|
||||
be, err = s3.Open(cfg)
|
||||
case "rest":
|
||||
return rest.Open(loc.Config.(rest.Config))
|
||||
be, err = rest.Open(loc.Config.(rest.Config))
|
||||
default:
|
||||
return nil, errors.Fatalf("invalid backend: %q", loc.Scheme)
|
||||
}
|
||||
|
||||
debug.Log("open", "invalid repository location: %v", s)
|
||||
return nil, errors.Fatalf("invalid scheme %q", loc.Scheme)
|
||||
if err != nil {
|
||||
return nil, errors.Fatalf("unable to open repo at %v: %v", s, err)
|
||||
}
|
||||
|
||||
return be, nil
|
||||
}
|
||||
|
||||
// Create the backend specified by URI.
|
||||
|
|
|
@ -7,17 +7,14 @@ func Cause(err error) error {
|
|||
return errors.Cause(err)
|
||||
}
|
||||
|
||||
// New creates a new error based on message.
|
||||
func New(message string) error {
|
||||
return errors.New(message)
|
||||
}
|
||||
// New creates a new error based on message. Wrapped so that this package does
|
||||
// not appear in the stack trace.
|
||||
var New = errors.New
|
||||
|
||||
// Errorf creates an error based on a format string and values.
|
||||
func Errorf(format string, args ...interface{}) error {
|
||||
return errors.Errorf(format, args...)
|
||||
}
|
||||
// Errorf creates an error based on a format string and values. Wrapped so that
|
||||
// this package does not appear in the stack trace.
|
||||
var Errorf = errors.Errorf
|
||||
|
||||
// Wrap wraps an error retrieved from outside of restic.
|
||||
func Wrap(err error, message string) error {
|
||||
return errors.Wrap(err, message)
|
||||
}
|
||||
// Wrap wraps an error retrieved from outside of restic. Wrapped so that this
|
||||
// package does not appear in the stack trace.
|
||||
var Wrap = errors.Wrap
|
||||
|
|
Loading…
Reference in a new issue