Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to the error messages on upload failures. #78

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/stashcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func main() {
if errMsg == "" {
errMsg = result.Error()
}
log.Errorln("Failure downloading " + lastSrc + ": " + errMsg)
log.Errorln("Failure transferring " + lastSrc + ": " + errMsg)
if stashcp.ErrorsRetryable() {
log.Errorln("Errors are retryable")
os.Exit(11)
Expand Down
12 changes: 12 additions & 0 deletions errorAccum.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ func IsRetryable(err error) bool {
}
return true
}
var hep *HttpErrResp
if errors.As(err, &hep) {
switch int(hep.Code) {
case http.StatusInternalServerError:
case http.StatusBadGateway:
case http.StatusServiceUnavailable:
case http.StatusGatewayTimeout:
return true
default:
return false
}
}
return false
}

Expand Down
16 changes: 14 additions & 2 deletions handle_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ func (e *StoppedTransferError) Error() string {
}


type HttpErrResp struct {
Code int
Err string
}

func (e *HttpErrResp) Error() string {
return e.Err
}


// SlowTransferError is an error that is returned when a transfer takes longer than the configured timeout
type SlowTransferError struct {
BytesTransferred int64
Expand Down Expand Up @@ -641,7 +651,8 @@ Loop:
// prior attempt.
if resp.HTTPResponse.StatusCode != 200 && resp.HTTPResponse.StatusCode != 206 {
log.Debugln("Got failure status code:", resp.HTTPResponse.StatusCode)
return 0, errors.New("failure status code")
return 0, &HttpErrResp{resp.HTTPResponse.StatusCode, fmt.Sprintf("Request failed (HTTP status %d): %s",
resp.HTTPResponse.StatusCode, resp.Err().Error())}
}
log.Debugln("HTTP Transfer was successful")
return resp.BytesComplete(), nil
Expand Down Expand Up @@ -760,7 +771,8 @@ Loop:
case response := <-responseChan:
if response.StatusCode != 200 {
log.Errorln("Got failure status code:", response.StatusCode)
lastError = errors.New("failure status code")
lastError = &HttpErrResp{response.StatusCode, fmt.Sprintf("Request failed (HTTP status %d)",
response.StatusCode)}
break Loop
}
break Loop
Expand Down
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,12 @@ func DoStashCPSingle(sourceFile string, destination string, methods []string, re
ns, err := MatchNamespace(dest_url.Path)
if err != nil {
log.Errorln("Failed to get namespace information:", err)
AddError(err)
return 0, err
}
return doWriteBack(source_url.Path, dest_url, ns)
_, err = doWriteBack(source_url.Path, dest_url, ns)
AddError(err)
return 0, err
}

if dest_url.Scheme == "file" {
Expand Down