fix: surface parsing errors instead of silently discarding them
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user