From 0d72c2bede9acc83ffba994f09388e9912ec3578 Mon Sep 17 00:00:00 2001 From: Yug Patel <5773665+Detoy@users.noreply.github.com> Date: Wed, 7 Oct 2026 14:32:16 +0530 Subject: [PATCH 1/2] Reject a -sites list with no site keys instead of panicking `crawl -sites ","` resolved to an empty key list but was accepted, so the single-site path indexed siteKeys[0] and panicked. `watch -sites ","` started and idled forever watching zero sites. Treat a -sites value with no keys as if it was not given. Both commands now print "one of -site, -sites, or --all-sites is required" and exit 1, and an empty -sites next to a -site no longer discards that -site. Fixes #13 --- cmd/doc-scraper/exec_test.go | 11 +++++++++++ cmd/doc-scraper/main.go | 15 ++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/cmd/doc-scraper/exec_test.go b/cmd/doc-scraper/exec_test.go index 75ebdfd..1858929 100644 --- a/cmd/doc-scraper/exec_test.go +++ b/cmd/doc-scraper/exec_test.go @@ -164,6 +164,17 @@ func TestResolveSiteKeys(t *testing.T) { _, _, ok = resolveSiteKeys("", "", false) assert.False(t, ok) + + // A -sites list with no keys selects nothing, so it is not a selector. + for _, sites := range []string{",", " , ,", " "} { + _, _, ok = resolveSiteKeys("", sites, false) + assert.False(t, ok, "-sites %q", sites) + } + + keys, warning, ok = resolveSiteKeys("a", ",", false) + assert.True(t, ok) + assert.Equal(t, []string{"a"}, keys) + assert.Empty(t, warning) } func TestLogHelpers(t *testing.T) { diff --git a/cmd/doc-scraper/main.go b/cmd/doc-scraper/main.go index 9e8e177..71bee58 100644 --- a/cmd/doc-scraper/main.go +++ b/cmd/doc-scraper/main.go @@ -167,6 +167,7 @@ func extraArgsError(fs *flag.FlagSet) error { // resolveSiteKeys picks the crawl target in precedence --all-sites > -sites > // -site. warning is non-empty when a lower-precedence selector was also set and // silently ignored, so a typo'd -site next to a valid -sites is not missed. +// A -sites list with no keys in it (e.g. ",") counts as not given. func resolveSiteKeys(siteKey, sites string, allSites bool) (siteKeys []string, warning string, ok bool) { if allSites { if sites != "" || siteKey != "" { @@ -174,16 +175,16 @@ func resolveSiteKeys(siteKey, sites string, allSites bool) (siteKeys []string, w } return nil, warning, true } - if sites != "" { + for _, s := range strings.Split(sites, ",") { + s = strings.TrimSpace(s) + if s != "" { + siteKeys = append(siteKeys, s) + } + } + if len(siteKeys) > 0 { if siteKey != "" { warning = "both -site and -sites given; using -sites and ignoring -site" } - for _, s := range strings.Split(sites, ",") { - s = strings.TrimSpace(s) - if s != "" { - siteKeys = append(siteKeys, s) - } - } return siteKeys, warning, true } if siteKey != "" { From 71944119107b85ab5581f56546d5e80b68c700a1 Mon Sep 17 00:00:00 2001 From: Yug Patel <5773665+Detoy@users.noreply.github.com> Date: Wed, 7 Oct 2026 19:28:05 +0530 Subject: [PATCH 2/2] Warn when an empty -sites list falls back to -site --- cmd/doc-scraper/exec_test.go | 2 +- cmd/doc-scraper/main.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/doc-scraper/exec_test.go b/cmd/doc-scraper/exec_test.go index 1858929..764336c 100644 --- a/cmd/doc-scraper/exec_test.go +++ b/cmd/doc-scraper/exec_test.go @@ -174,7 +174,7 @@ func TestResolveSiteKeys(t *testing.T) { keys, warning, ok = resolveSiteKeys("a", ",", false) assert.True(t, ok) assert.Equal(t, []string{"a"}, keys) - assert.Empty(t, warning) + assert.Equal(t, "-sites has no site keys; using -site", warning) } func TestLogHelpers(t *testing.T) { diff --git a/cmd/doc-scraper/main.go b/cmd/doc-scraper/main.go index 71bee58..4f3beb6 100644 --- a/cmd/doc-scraper/main.go +++ b/cmd/doc-scraper/main.go @@ -167,7 +167,8 @@ func extraArgsError(fs *flag.FlagSet) error { // resolveSiteKeys picks the crawl target in precedence --all-sites > -sites > // -site. warning is non-empty when a lower-precedence selector was also set and // silently ignored, so a typo'd -site next to a valid -sites is not missed. -// A -sites list with no keys in it (e.g. ",") counts as not given. +// A -sites list with no keys in it (e.g. ",") counts as not given; if -site +// is also set it is used, with a warning. func resolveSiteKeys(siteKey, sites string, allSites bool) (siteKeys []string, warning string, ok bool) { if allSites { if sites != "" || siteKey != "" { @@ -188,7 +189,10 @@ func resolveSiteKeys(siteKey, sites string, allSites bool) (siteKeys []string, w return siteKeys, warning, true } if siteKey != "" { - return []string{siteKey}, "", true + if sites != "" { + warning = "-sites has no site keys; using -site" + } + return []string{siteKey}, warning, true } return nil, "", false }