Merge pull request #1045 from abperiasamy/error2probe
convert remaining typed errors to probe errors
This commit is contained in:
+1
-1
@@ -74,7 +74,7 @@ func aliasExpand(aliasedURL string, aliases map[string]string) (string, *probe.E
|
||||
trimmedURL := expandedURL + "/" + strings.TrimPrefix(strings.TrimPrefix(splits[1], "/"), "\\")
|
||||
u, err := client.Parse(trimmedURL)
|
||||
if err != nil {
|
||||
return aliasedURL, probe.NewError(eInvalidURL{URL: aliasedURL})
|
||||
return aliasedURL, errInvalidURL(aliasedURL).Trace()
|
||||
}
|
||||
return u.String(), nil
|
||||
}
|
||||
|
||||
+2
-2
@@ -165,7 +165,7 @@ func getNewClient(urlStr string, auth hostConfig) (client.Client, *probe.Error)
|
||||
case client.Filesystem:
|
||||
return fs.New(urlStr)
|
||||
}
|
||||
return nil, probe.NewError(eInitClient{URL: urlStr})
|
||||
return nil, errInitClient(urlStr).Trace()
|
||||
}
|
||||
|
||||
// url2Stat - Returns client, config and its stat Content from the URL
|
||||
@@ -199,7 +199,7 @@ func isValidURL(url string) bool {
|
||||
|
||||
func url2Client(url string) (client.Client, *probe.Error) {
|
||||
if !isValidURL(url) {
|
||||
return nil, probe.NewError(eInvalidURL{URL: url})
|
||||
return nil, errInvalidURL(url).Trace()
|
||||
}
|
||||
urlconfig, err := getHostConfig(url)
|
||||
if err != nil {
|
||||
|
||||
@@ -236,7 +236,7 @@ func prepareCopyURLsTypeA(sourceURL string, targetURL string) copyURLs {
|
||||
}
|
||||
if !sourceContent.Type.IsRegular() {
|
||||
// Source is not a regular file
|
||||
return copyURLs{Error: probe.NewError(eInvalidSource{URL: sourceURL})}
|
||||
return copyURLs{Error: errInvalidSource(sourceURL).Trace()}
|
||||
}
|
||||
// All OK.. We can proceed. Type A
|
||||
sourceContent.Name = sourceURL
|
||||
@@ -253,19 +253,19 @@ func prepareCopyURLsTypeB(sourceURL string, targetURL string) copyURLs {
|
||||
}
|
||||
if !sourceContent.Type.IsRegular() {
|
||||
// Source is not a regular file.
|
||||
return copyURLs{Error: probe.NewError(eInvalidSource{URL: sourceURL})}
|
||||
return copyURLs{Error: errInvalidSource(sourceURL).Trace()}
|
||||
}
|
||||
|
||||
// All OK.. We can proceed. Type B: source is a file, target is a folder and exists.
|
||||
{
|
||||
sourceURLParse, err := client.Parse(sourceURL)
|
||||
if err != nil {
|
||||
return copyURLs{Error: probe.NewError(eInvalidSource{URL: sourceURL})}
|
||||
return copyURLs{Error: errInvalidSource(sourceURL).Trace()}
|
||||
}
|
||||
|
||||
targetURLParse, err := client.Parse(targetURL)
|
||||
if err != nil {
|
||||
return copyURLs{Error: probe.NewError(eInvalidTarget{URL: targetURL})}
|
||||
return copyURLs{Error: errInvalidTarget(targetURL).Trace()}
|
||||
}
|
||||
targetURLParse.Path = filepath.Join(targetURLParse.Path, filepath.Base(sourceURLParse.Path))
|
||||
return prepareCopyURLsTypeA(sourceURL, targetURLParse.String())
|
||||
@@ -280,7 +280,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs {
|
||||
defer close(copyURLsCh)
|
||||
if !isURLRecursive(sourceURL) {
|
||||
// Source is not of recursive type.
|
||||
copyURLsCh <- copyURLs{Error: probe.NewError(eSourceNotRecursive{URL: sourceURL})}
|
||||
copyURLsCh <- copyURLs{Error: errSourceNotRecursive(sourceURL).Trace()}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs {
|
||||
|
||||
if !sourceContent.Type.IsDir() {
|
||||
// Source is not a dir.
|
||||
copyURLsCh <- copyURLs{Error: probe.NewError(eSourceIsNotDir{URL: sourceURL})}
|
||||
copyURLsCh <- copyURLs{Error: errSourceIsNotDir(sourceURL).Trace()}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -314,13 +314,13 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs {
|
||||
// All OK.. We can proceed. Type B: source is a file, target is a folder and exists.
|
||||
sourceURLParse, err := client.Parse(sourceURL)
|
||||
if err != nil {
|
||||
copyURLsCh <- copyURLs{Error: probe.NewError(eInvalidSource{URL: sourceURL})}
|
||||
copyURLsCh <- copyURLs{Error: errInvalidSource(sourceURL).Trace()}
|
||||
continue
|
||||
}
|
||||
|
||||
targetURLParse, err := client.Parse(targetURL)
|
||||
if err != nil {
|
||||
copyURLsCh <- copyURLs{Error: probe.NewError(eInvalidTarget{URL: targetURL})}
|
||||
copyURLsCh <- copyURLs{Error: errInvalidTarget(targetURL).Trace()}
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -330,7 +330,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs {
|
||||
sourceContentURL := sourceURLDelimited + sourceContentName
|
||||
sourceContentParse, err := client.Parse(sourceContentURL)
|
||||
if err != nil {
|
||||
copyURLsCh <- copyURLs{Error: probe.NewError(eInvalidSource{URL: sourceContentName})}
|
||||
copyURLsCh <- copyURLs{Error: errInvalidSource(sourceContentName).Trace()}
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ func doDiffObjects(firstURL, secondURL string, ch chan DiffMessage) {
|
||||
}
|
||||
default:
|
||||
ch <- DiffMessage{
|
||||
Error: probe.NewError(eNotAnObject{URL: firstURL}),
|
||||
Error: errNotAnObject(firstURL).Trace(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
+2
-2
@@ -50,12 +50,12 @@ func getHostConfig(URL string) (hostConfig, *probe.Error) {
|
||||
for globURL, hostCfg := range config.Hosts {
|
||||
match, err := filepath.Match(globURL, url.Host)
|
||||
if err != nil {
|
||||
return hostConfig{}, probe.NewError(eInvalidGlobURL{glob: globURL, request: URL})
|
||||
return hostConfig{}, errInvalidGlobURL(globURL, URL).Trace()
|
||||
}
|
||||
if match {
|
||||
return hostCfg, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return hostConfig{}, probe.NewError(eNoMatchingHost{URL: URL})
|
||||
return hostConfig{}, errNoMatchingHost(URL).Trace()
|
||||
}
|
||||
|
||||
+1
-1
@@ -197,7 +197,7 @@ func prepareMirrorURLs(sourceURL string, targetURLs []string) <-chan mirrorURLs
|
||||
}
|
||||
// if one of the targets is not dir exit
|
||||
if !targetContent.Type.IsDir() {
|
||||
mirrorURLsCh <- mirrorURLs{Error: probe.NewError(eInvalidTarget{URL: targetURL})}
|
||||
mirrorURLsCh <- mirrorURLs{Error: errInvalidTarget(targetURL).Trace()}
|
||||
return
|
||||
}
|
||||
// special case, be extremely careful before changing this behavior - will lead to data loss
|
||||
|
||||
+37
-59
@@ -26,69 +26,47 @@ var (
|
||||
errDummy = func() *probe.Error {
|
||||
return probe.NewError(errors.New("")).Untrace()
|
||||
}
|
||||
|
||||
errInvalidArgument = func() *probe.Error {
|
||||
return probe.NewError(errors.New("Invalid arguments provided, cannot proceed.")).Untrace()
|
||||
}
|
||||
|
||||
errSourceListEmpty = func() *probe.Error {
|
||||
return probe.NewError(errors.New("Source argument list is empty.")).Untrace()
|
||||
}
|
||||
|
||||
errInvalidGlobURL = func(glob, request string) *probe.Error {
|
||||
return probe.NewError(errors.New("Error reading glob URL ‘" + glob + "’ while comparing with ‘" + request + "’.")).Untrace()
|
||||
}
|
||||
|
||||
errInvalidURL = func(URL string) *probe.Error {
|
||||
return probe.NewError(errors.New("Invalid URL ‘" + URL + "’.")).Untrace()
|
||||
}
|
||||
|
||||
errNoMatchingHost = func(URL string) *probe.Error {
|
||||
return probe.NewError(errors.New("No matching host found for the given URL ‘" + URL + "’.")).Untrace()
|
||||
}
|
||||
|
||||
errInitClient = func(URL string) *probe.Error {
|
||||
return probe.NewError(errors.New("Unable to initialize client for URL ‘" + URL + "’.")).Untrace()
|
||||
}
|
||||
|
||||
errInvalidSource = func(URL string) *probe.Error {
|
||||
return probe.NewError(errors.New("Invalid source ‘" + URL + "’.")).Untrace()
|
||||
}
|
||||
|
||||
errInvalidTarget = func(URL string) *probe.Error {
|
||||
return probe.NewError(errors.New("Invalid target ‘" + URL + "’.")).Untrace()
|
||||
}
|
||||
|
||||
errSourceNotRecursive = func(URL string) *probe.Error {
|
||||
return probe.NewError(errors.New("Source ‘" + URL + "’ is not recursive.")).Untrace()
|
||||
}
|
||||
|
||||
errSourceIsNotDir = func(URL string) *probe.Error {
|
||||
return probe.NewError(errors.New("Source ‘" + URL + "’ is not a folder.")).Untrace()
|
||||
}
|
||||
errNotAnObject = func(URL string) *probe.Error {
|
||||
return probe.NewError(errors.New("‘" + URL + "’ is not an object.")).Untrace()
|
||||
}
|
||||
)
|
||||
|
||||
type eInvalidGlobURL struct {
|
||||
glob string
|
||||
request string
|
||||
}
|
||||
|
||||
func (e eInvalidGlobURL) Error() string {
|
||||
return "Error reading glob URL ‘" + e.glob + "’ while comparing with ‘" + e.request + "’."
|
||||
}
|
||||
|
||||
type eInvalidURL struct {
|
||||
URL string
|
||||
}
|
||||
|
||||
func (e eInvalidURL) Error() string {
|
||||
return "Invalid URL " + e.URL
|
||||
}
|
||||
|
||||
type eNoMatchingHost eInvalidURL
|
||||
|
||||
func (e eNoMatchingHost) Error() string {
|
||||
return "No matching host found for the given URL ‘" + e.URL + "’."
|
||||
}
|
||||
|
||||
type eInitClient eInvalidURL
|
||||
|
||||
func (e eInitClient) Error() string {
|
||||
return "Unable to initialize client for URL ‘" + e.URL + "’."
|
||||
}
|
||||
|
||||
type eInvalidSource eInvalidURL
|
||||
|
||||
func (e eInvalidSource) Error() string {
|
||||
return "Invalid source " + e.URL
|
||||
}
|
||||
|
||||
type eInvalidTarget eInvalidURL
|
||||
|
||||
func (e eInvalidTarget) Error() string {
|
||||
return "Invalid target " + e.URL
|
||||
}
|
||||
|
||||
type eSourceNotRecursive eInvalidURL
|
||||
|
||||
func (e eSourceNotRecursive) Error() string {
|
||||
return "Source ‘" + e.URL + "’ is not recursive."
|
||||
}
|
||||
|
||||
type eSourceIsNotDir eInvalidURL
|
||||
|
||||
func (e eSourceIsNotDir) Error() string {
|
||||
return "Source ‘" + e.URL + "’ is not a folder."
|
||||
}
|
||||
|
||||
type eNotAnObject eInvalidURL
|
||||
|
||||
func (e eNotAnObject) Error() string {
|
||||
return "‘" + e.URL + "’ is not an object."
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func getCanonicalizedURL(arg string, aliases map[string]string) (urlStr string,
|
||||
}
|
||||
if _, err := client.Parse(urlStr); err != nil {
|
||||
// Not a valid URL. Return error
|
||||
return "", probe.NewError(eInvalidURL{urlStr})
|
||||
return "", errInvalidURL(urlStr).Trace()
|
||||
}
|
||||
return urlStr, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user