diff options
| author | Shulhan <ms@kilabit.info> | 2025-05-31 19:21:06 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-05-31 19:25:48 +0700 |
| commit | 95c71232fc977d68aeae0c14aab1e91c9d3e9605 (patch) | |
| tree | 904f80d30945e11f11154e4522c76e26f6a06384 | |
| parent | df380fa8fefbb04ac3f9c29198e5535364c67865 (diff) | |
| download | jarink-95c71232fc977d68aeae0c14aab1e91c9d3e9605.tar.xz | |
all: record the error when checking the links
The error message can help user to debug the problems with links.
| -rw-r--r-- | cmd/deadlinks/main.go | 2 | ||||
| -rw-r--r-- | deadlinks_test.go | 10 | ||||
| -rw-r--r-- | result.go | 5 | ||||
| -rw-r--r-- | worker.go | 3 |
4 files changed, 14 insertions, 6 deletions
diff --git a/cmd/deadlinks/main.go b/cmd/deadlinks/main.go index d018c9d..16057ee 100644 --- a/cmd/deadlinks/main.go +++ b/cmd/deadlinks/main.go @@ -89,6 +89,7 @@ the image src attribute ("<img src=..."). }, { "Link": "https://external.com/link", + "Error": "Internal server error", "Code": 500 } ], @@ -99,6 +100,7 @@ the image src attribute ("<img src=..."). }, { "Link": "https://external.org/link", + "Error": "Internal server error", "Code": 500 } ] diff --git a/deadlinks_test.go b/deadlinks_test.go index 8b7d83e..c93e384 100644 --- a/deadlinks_test.go +++ b/deadlinks_test.go @@ -100,8 +100,9 @@ func TestDeadLinks_Scan(t *testing.T) { Link: `http://127.0.0.1:abc`, Code: deadlinks.StatusBadLink, }, { - Link: `http:/127.0.0.1:11836`, - Code: deadlinks.StatusBadLink, + Link: `http:/127.0.0.1:11836`, + Error: `Head "http:/127.0.0.1:11836": http: no Host in request URL`, + Code: deadlinks.StatusBadLink, }, }, testUrl + `/broken.html`: []deadlinks.Broken{ @@ -137,8 +138,9 @@ func TestDeadLinks_Scan(t *testing.T) { Link: `http://127.0.0.1:abc`, Code: deadlinks.StatusBadLink, }, { - Link: `http:/127.0.0.1:11836`, - Code: deadlinks.StatusBadLink, + Link: `http:/127.0.0.1:11836`, + Error: `Head "http:/127.0.0.1:11836": http: no Host in request URL`, + Code: deadlinks.StatusBadLink, }, }, testUrl + `/broken.html`: []deadlinks.Broken{ @@ -10,8 +10,9 @@ import ( // Broken store the link with its HTTP status. type Broken struct { - Link string - Code int + Link string + Error string `json:"omitempty"` + Code int } // Result store the result of Scan. @@ -196,6 +196,9 @@ func (wrk *worker) markDead(linkq linkQueue) { Link: linkq.url, Code: linkq.status, } + if linkq.errScan != nil { + brokenLink.Error = linkq.errScan.Error() + } listBroken = append(listBroken, brokenLink) wrk.result.PageLinks[parentUrl] = listBroken |
