fix: propagate errors from DuckDuckGo search and GetResults
Some checks failed
CI / test (pull_request) Failing after 6m12s
CI / vet (pull_request) Failing after 6m12s
CI / build (pull_request) Failing after 6m15s

- Change SearchPage.GetResults() to return ([]Result, error) so ForEach
  errors are no longer silently discarded
- Fix Search() to return the ForEach error instead of nil
- Update cmd caller to check GetResults() errors

Closes #5, #6

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-15 16:16:04 +00:00
parent 49f294e884
commit a12c9f7cb6
3 changed files with 14 additions and 8 deletions

View File

@@ -9,7 +9,7 @@ import (
type SearchPage interface {
io.Closer
GetResults() []Result
GetResults() ([]Result, error)
LoadMore() error
}
@@ -17,11 +17,10 @@ type searchPage struct {
doc extractor.Document
}
func (s searchPage) GetResults() []Result {
func (s searchPage) GetResults() ([]Result, error) {
var res []Result
var err error
err = s.doc.ForEach(`article[id^="r1-"]`, func(n extractor.Node) error {
err := s.doc.ForEach(`article[id^="r1-"]`, func(n extractor.Node) error {
var r Result
links := n.Select(`a[href][target="_self"]`)
@@ -30,6 +29,7 @@ func (s searchPage) GetResults() []Result {
return nil
}
var err error
r.URL, err = links[0].Attr(`href`)
if err != nil {
@@ -53,7 +53,7 @@ func (s searchPage) GetResults() []Result {
return nil
})
return res
return res, err
}
func (s searchPage) LoadMore() error {