github.com/golang/dep@v0.5.4/gps/source_errors.go (about) 1 // Copyright 2017 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package gps 6 7 import ( 8 "github.com/Masterminds/vcs" 9 "github.com/pkg/errors" 10 ) 11 12 // unwrapVcsErr recognizes *vcs.LocalError and *vsc.RemoteError, and returns a form 13 // preserving the actual vcs command output and error, in addition to the message. 14 // All other types pass through unchanged. 15 func unwrapVcsErr(err error) error { 16 var cause error 17 var out, msg string 18 19 switch t := err.(type) { 20 case *vcs.LocalError: 21 cause, out, msg = t.Original(), t.Out(), t.Error() 22 case *vcs.RemoteError: 23 cause, out, msg = t.Original(), t.Out(), t.Error() 24 25 default: 26 return err 27 } 28 29 if cause == nil { 30 cause = errors.New(out) 31 } else { 32 cause = errors.Wrap(cause, out) 33 } 34 return errors.Wrap(cause, msg) 35 }