2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-16 18:15:20 +00:00

Merge pull request #623 from restic/fix-622

Improve error messages for open repo
This commit is contained in:
Alexander Neumann 2016-09-18 14:04:30 +02:00
commit c5763e59d5
2 changed files with 23 additions and 19 deletions

View File

@ -296,16 +296,18 @@ func open(s string) (restic.Backend, error) {
debug.Log("open", "parsing location %v", s) debug.Log("open", "parsing location %v", s)
loc, err := location.Parse(s) loc, err := location.Parse(s)
if err != nil { if err != nil {
return nil, err return nil, errors.Fatalf("parsing repository location failed: %v", err)
} }
var be restic.Backend
switch loc.Scheme { switch loc.Scheme {
case "local": case "local":
debug.Log("open", "opening local repository at %#v", loc.Config) 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": case "sftp":
debug.Log("open", "opening sftp repository at %#v", loc.Config) 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": case "s3":
cfg := loc.Config.(s3.Config) cfg := loc.Config.(s3.Config)
if cfg.KeyID == "" { if cfg.KeyID == "" {
@ -317,13 +319,18 @@ func open(s string) (restic.Backend, error) {
} }
debug.Log("open", "opening s3 repository at %#v", cfg) debug.Log("open", "opening s3 repository at %#v", cfg)
return s3.Open(cfg) be, err = s3.Open(cfg)
case "rest": 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) if err != nil {
return nil, errors.Fatalf("invalid scheme %q", loc.Scheme) return nil, errors.Fatalf("unable to open repo at %v: %v", s, err)
}
return be, nil
} }
// Create the backend specified by URI. // Create the backend specified by URI.

View File

@ -7,17 +7,14 @@ func Cause(err error) error {
return errors.Cause(err) return errors.Cause(err)
} }
// New creates a new error based on message. // New creates a new error based on message. Wrapped so that this package does
func New(message string) error { // not appear in the stack trace.
return errors.New(message) var New = errors.New
}
// Errorf creates an error based on a format string and values. // Errorf creates an error based on a format string and values. Wrapped so that
func Errorf(format string, args ...interface{}) error { // this package does not appear in the stack trace.
return errors.Errorf(format, args...) var Errorf = errors.Errorf
}
// Wrap wraps an error retrieved from outside of restic. // Wrap wraps an error retrieved from outside of restic. Wrapped so that this
func Wrap(err error, message string) error { // package does not appear in the stack trace.
return errors.Wrap(err, message) var Wrap = errors.Wrap
}