aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2025-05-31 19:21:06 +0700
committerShulhan <ms@kilabit.info>2025-05-31 19:25:48 +0700
commit95c71232fc977d68aeae0c14aab1e91c9d3e9605 (patch)
tree904f80d30945e11f11154e4522c76e26f6a06384
parentdf380fa8fefbb04ac3f9c29198e5535364c67865 (diff)
downloadjarink-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.go2
-rw-r--r--deadlinks_test.go10
-rw-r--r--result.go5
-rw-r--r--worker.go3
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{
diff --git a/result.go b/result.go
index 1fc11c5..6fdc817 100644
--- a/result.go
+++ b/result.go
@@ -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.
diff --git a/worker.go b/worker.go
index 1b1780d..bc66a98 100644
--- a/worker.go
+++ b/worker.go
@@ -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