fix: surface parsing errors instead of silently discarding them
All checks were successful
CI / vet (pull_request) Successful in 1m10s
CI / build (pull_request) Successful in 1m21s
CI / test (pull_request) Successful in 1m28s

Return errors for required fields (ID, price) and log warnings for
optional fields (title, description, unit price) across all site
extractors instead of silently discarding them with _ =.

Closes #24
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-15 16:31:56 +00:00
parent 7f24e97131
commit a9711ce904
4 changed files with 77 additions and 27 deletions

View File

@@ -2,9 +2,10 @@ package duckduckgo
import (
"fmt"
"gitea.stevedudenhoeffer.com/steve/go-extractor"
"io"
"log/slog"
"gitea.stevedudenhoeffer.com/steve/go-extractor"
)
type SearchPage interface {
@@ -44,13 +45,19 @@ func extractResults(doc extractor.Node) ([]Result, error) {
titles := n.Select("h2")
if len(titles) != 0 {
r.Title, _ = titles[0].Text()
r.Title, err = titles[0].Text()
if err != nil {
slog.Warn("failed to get result title", "err", err)
}
}
descriptions := n.Select("span > span")
if len(descriptions) != 0 {
r.Description, _ = descriptions[0].Text()
r.Description, err = descriptions[0].Text()
if err != nil {
slog.Warn("failed to get result description", "err", err)
}
}
res = append(res, r)