Skip to content

Commit

Permalink
Fix bad error handling in checkExternal
Browse files Browse the repository at this point in the history
Sometimes the error message from http.Client is different in Go 1.15 for client timeouts.
The messages causing issues contain "dial tcp" which was caught before Client.Timeout.

This fix just moves the handler for "Client.Timeout" above "dial tcp".

Will close #148
  • Loading branch information
wjdp committed Jan 15, 2021
1 parent 2d792c9 commit a65ff20
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions htmltest/check-link.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,6 @@ func (hT *HTMLTest) checkExternal(ref *htmldoc.Reference) {
<-hT.httpChannel // Bump off http concurrency limiter

if err != nil {
if strings.Contains(err.Error(), "dial tcp") {
// Remove long prefix
prefix := "Get " + urlStr + ": dial tcp: lookup "
cleanedMessage := strings.TrimPrefix(err.Error(), prefix)
// Add error
hT.issueStore.AddIssue(issues.Issue{
Level: issueLevel,
Message: cleanedMessage,
Reference: ref,
})
return
}
if strings.Contains(err.Error(), "Client.Timeout") {
hT.issueStore.AddIssue(issues.Issue{
Level: issueLevel,
Expand All @@ -215,6 +203,20 @@ func (hT *HTMLTest) checkExternal(ref *htmldoc.Reference) {
}
}

// More generic, should be kept below more specific cases
if strings.Contains(err.Error(), "dial tcp") {
// Remove long prefix
prefix := "Get " + urlStr + ": dial tcp: lookup "
cleanedMessage := strings.TrimPrefix(err.Error(), prefix)
// Add error
hT.issueStore.AddIssue(issues.Issue{
Level: issueLevel,
Message: cleanedMessage,
Reference: ref,
})
return
}

// Unhandled client error, return generic error
hT.issueStore.AddIssue(issues.Issue{
Level: issueLevel,
Expand Down

0 comments on commit a65ff20

Please sign in to comment.