From 6029d170fb71c38d8377f6f13945ff45346ce077 Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Mon, 9 Nov 2026 01:42:15 -0500 Subject: [PATCH 1/4] fix(adsense): show report warnings and truncation in table output adsense reports query JSON output includes the API's warnings and totalMatchedRows, but table and --plain output dropped both, so a report cut short by --max or the 100,000-row limit looked complete. Print them on stderr, keeping stdout parseable. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 + internal/cmd/adsense_report_warnings_test.go | 54 ++++++++++++++++++++ internal/cmd/adsense_reports.go | 11 ++++ 3 files changed, 67 insertions(+) create mode 100644 internal/cmd/adsense_report_warnings_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 861521fad..d8d74ad17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.48.1 - Unreleased +- AdSense: show the report's API warnings and a "showing N of M matched rows" note on stderr in `adsense reports query` table and `--plain` output, as JSON output already includes them. A report cut short by `--max` or by the 100,000-row limit previously looked complete. — thanks @saariuslystoned. + ## 0.48.0 - 2026-11-05 **Highlights:** New backups stay local until you configure a remote; existing configurations keep working. Store service-account keys in the keyring, search Gmail IDs efficiently, and use environment-backed watch tokens, with Calendar fixes and security dependency updates. diff --git a/internal/cmd/adsense_report_warnings_test.go b/internal/cmd/adsense_report_warnings_test.go new file mode 100644 index 000000000..4e70ec305 --- /dev/null +++ b/internal/cmd/adsense_report_warnings_test.go @@ -0,0 +1,54 @@ +package cmd + +import ( + "encoding/json" + "net/http" + "strings" + "testing" +) + +// A truncated report (totalMatchedRows above the rows returned) and the API's +// own warnings reach JSON output; table and --plain output must not drop them. +func TestExecute_AdSenseReportsQuery_TableShowsTruncationAndWarnings(t *testing.T) { + svc := newAdSenseTestService(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if !(r.Method == http.MethodGet && strings.Contains(r.URL.Path, "/reports:generate")) { + http.NotFound(w, r) + return + } + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(map[string]any{ + "headers": []map[string]any{ + {"name": "DATE", "type": "DIMENSION"}, + {"name": "ESTIMATED_EARNINGS", "type": "METRIC_CURRENCY"}, + }, + "rows": []map[string]any{ + {"cells": []map[string]any{{"value": "2026-02-01"}, {"value": "1.23"}}}, + {"cells": []map[string]any{{"value": "2026-02-02"}, {"value": "4.56"}}}, + }, + "totalMatchedRows": "250000", + "warnings": []string{"Some requested metrics are not available for this date range."}, + }) + })) + for _, mode := range []string{"--plain", ""} { + args := []string{"--account", "a@b.com", "adsense", "reports", "query", "pub-123", "--metrics", "estimated_earnings"} + if mode != "" { + args = append([]string{mode}, args...) + } + result := executeWithAdSenseTestService(t, args, svc) + if result.err != nil { + t.Fatalf("%q: Execute: %v", mode, result.err) + } + if !strings.Contains(result.stdout, "2026-02-02") { + t.Fatalf("%q: rows missing from stdout: %q", mode, result.stdout) + } + if strings.Contains(result.stdout, "250000") || strings.Contains(result.stdout, "not available") { + t.Fatalf("%q: notes must stay off stdout: %q", mode, result.stdout) + } + if !strings.Contains(result.stderr, "2 of 250000") { + t.Fatalf("%q: want truncation note on stderr, got %q", mode, result.stderr) + } + if !strings.Contains(result.stderr, "Some requested metrics are not available") { + t.Fatalf("%q: want API warning on stderr, got %q", mode, result.stderr) + } + } +} diff --git a/internal/cmd/adsense_reports.go b/internal/cmd/adsense_reports.go index cf9acb8f7..f5581c19b 100644 --- a/internal/cmd/adsense_reports.go +++ b/internal/cmd/adsense_reports.go @@ -138,6 +138,17 @@ func writeAdSenseReportResult( return failEmptyExit(failEmpty) } + // JSON carries these fields; keep them visible here too, on stderr so + // stdout stays parseable. + for _, warning := range resp.Warnings { + if warning = strings.TrimSpace(warning); warning != "" { + u.Err().Linef("# Warning: %s", warning) + } + } + if resp.TotalMatchedRows > int64(len(resp.Rows)) { + u.Err().Linef("# Showing %d of %d matched rows; raise --max (up to 100000) or narrow the report to see more", len(resp.Rows), resp.TotalMatchedRows) + } + headers := adSenseReportHeaderNames(resp.Headers, dimensions, metrics) w, flush := tableWriter(ctx) From dda7dab26328a5126f034b95fbbd0a8c65db590f Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Mon, 9 Nov 2026 01:59:51 -0500 Subject: [PATCH 2/4] fix(adsense): show report warnings for empty tables too The empty-report early return ran before the new stderr notes, so warnings explaining an empty report were still dropped in table and --plain output. Print the notes first. Co-Authored-By: Claude Opus 5.5 --- internal/cmd/adsense_report_warnings_test.go | 25 ++++++++++++++++++++ internal/cmd/adsense_reports.go | 10 ++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/internal/cmd/adsense_report_warnings_test.go b/internal/cmd/adsense_report_warnings_test.go index 4e70ec305..7430dacb4 100644 --- a/internal/cmd/adsense_report_warnings_test.go +++ b/internal/cmd/adsense_report_warnings_test.go @@ -52,3 +52,28 @@ func TestExecute_AdSenseReportsQuery_TableShowsTruncationAndWarnings(t *testing. } } } + +// An empty report can still carry API warnings, which explain why no rows came back. +func TestExecute_AdSenseReportsQuery_EmptyTableStillShowsWarnings(t *testing.T) { + svc := newAdSenseTestService(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(map[string]any{ + "headers": []map[string]any{{"name": "ESTIMATED_EARNINGS", "type": "METRIC_CURRENCY"}}, + "rows": []any{}, + "warnings": []string{"Data for this date range is not available yet."}, + }) + })) + for _, mode := range []string{"--plain", ""} { + args := []string{"--account", "a@b.com", "adsense", "reports", "query", "pub-123", "--metrics", "estimated_earnings"} + if mode != "" { + args = append([]string{mode}, args...) + } + result := executeWithAdSenseTestService(t, args, svc) + if result.err != nil { + t.Fatalf("%q: Execute: %v", mode, result.err) + } + if !strings.Contains(result.stderr, "Data for this date range is not available yet.") || !strings.Contains(result.stderr, "No AdSense report rows") { + t.Fatalf("%q: want the warning and the empty-report note on stderr, got %q", mode, result.stderr) + } + } +} diff --git a/internal/cmd/adsense_reports.go b/internal/cmd/adsense_reports.go index f5581c19b..6aa97236a 100644 --- a/internal/cmd/adsense_reports.go +++ b/internal/cmd/adsense_reports.go @@ -133,11 +133,6 @@ func writeAdSenseReportResult( return nil } - if len(resp.Rows) == 0 { - u.Err().Println("No AdSense report rows") - return failEmptyExit(failEmpty) - } - // JSON carries these fields; keep them visible here too, on stderr so // stdout stays parseable. for _, warning := range resp.Warnings { @@ -149,6 +144,11 @@ func writeAdSenseReportResult( u.Err().Linef("# Showing %d of %d matched rows; raise --max (up to 100000) or narrow the report to see more", len(resp.Rows), resp.TotalMatchedRows) } + if len(resp.Rows) == 0 { + u.Err().Println("No AdSense report rows") + return failEmptyExit(failEmpty) + } + headers := adSenseReportHeaderNames(resp.Headers, dimensions, metrics) w, flush := tableWriter(ctx) From 90e91991a27dc2bac89fc1e43a41aa0cf67b7911 Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Mon, 9 Nov 2026 02:04:05 -0500 Subject: [PATCH 3/4] docs(changelog): reference #1324 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8d74ad17..b6b27d30a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 0.48.1 - Unreleased -- AdSense: show the report's API warnings and a "showing N of M matched rows" note on stderr in `adsense reports query` table and `--plain` output, as JSON output already includes them. A report cut short by `--max` or by the 100,000-row limit previously looked complete. — thanks @saariuslystoned. +- AdSense: show the report's API warnings and a "showing N of M matched rows" note on stderr in `adsense reports query` table and `--plain` output, as JSON output already includes them. A report cut short by `--max` or by the 100,000-row limit previously looked complete. (#1324) — thanks @saariuslystoned. ## 0.48.0 - 2026-11-05 From 44384daa263830c83a4867580d11709d78348bcc Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Mon, 9 Nov 2026 11:21:29 -0500 Subject: [PATCH 4/4] fix(adsense): give saved reports a truncation hint they can follow Saved reports have no --max flag, so suggest narrowing the saved report instead. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- internal/cmd/adsense_report_warnings_test.go | 25 +++++++++++++++++++- internal/cmd/adsense_reports.go | 7 +++--- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6b27d30a..ba45aeaec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 0.48.1 - Unreleased -- AdSense: show the report's API warnings and a "showing N of M matched rows" note on stderr in `adsense reports query` table and `--plain` output, as JSON output already includes them. A report cut short by `--max` or by the 100,000-row limit previously looked complete. (#1324) — thanks @saariuslystoned. +- AdSense: show the report's API warnings and a "showing N of M matched rows" note on stderr in `adsense reports query` table and `--plain` output (and `adsense reports saved query`), as JSON output already includes them. A report cut short by `--max` or by the 100,000-row limit previously looked complete. (#1324) — thanks @saariuslystoned. ## 0.48.0 - 2026-11-05 diff --git a/internal/cmd/adsense_report_warnings_test.go b/internal/cmd/adsense_report_warnings_test.go index 7430dacb4..0a57a2be3 100644 --- a/internal/cmd/adsense_report_warnings_test.go +++ b/internal/cmd/adsense_report_warnings_test.go @@ -11,7 +11,7 @@ import ( // own warnings reach JSON output; table and --plain output must not drop them. func TestExecute_AdSenseReportsQuery_TableShowsTruncationAndWarnings(t *testing.T) { svc := newAdSenseTestService(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if !(r.Method == http.MethodGet && strings.Contains(r.URL.Path, "/reports:generate")) { + if !(r.Method == http.MethodGet && strings.Contains(r.URL.Path, ":generate")) { http.NotFound(w, r) return } @@ -77,3 +77,26 @@ func TestExecute_AdSenseReportsQuery_EmptyTableStillShowsWarnings(t *testing.T) } } } + +// Saved reports have no --max flag, so their truncation note must not suggest one. +func TestExecute_AdSenseSavedReportTruncationHintHasNoMaxFlag(t *testing.T) { + svc := newAdSenseTestService(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if !strings.Contains(r.URL.Path, "/saved:generate") { + http.NotFound(w, r) + return + } + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(map[string]any{ + "headers": []map[string]any{{"name": "DATE", "type": "DIMENSION"}}, + "rows": []map[string]any{{"cells": []map[string]any{{"value": "2026-02-01"}}}}, + "totalMatchedRows": "250000", + }) + })) + result := executeWithAdSenseTestService(t, []string{"--plain", "--account", "a@b.com", "adsense", "reports", "saved", "query", "accounts/pub-123/reports/report-1"}, svc) + if result.err != nil { + t.Fatalf("Execute: %v", result.err) + } + if !strings.Contains(result.stderr, "1 of 250000") || strings.Contains(result.stderr, "--max") { + t.Fatalf("want a truncation note without --max, got %q", result.stderr) + } +} diff --git a/internal/cmd/adsense_reports.go b/internal/cmd/adsense_reports.go index 6aa97236a..a23ed5c1d 100644 --- a/internal/cmd/adsense_reports.go +++ b/internal/cmd/adsense_reports.go @@ -92,7 +92,7 @@ func (c *AdSenseReportsQueryCmd) Run(ctx context.Context, flags *RootFlags) erro return err } - return writeAdSenseReportResult(ctx, u, plan.Account, plan.Dimensions, plan.Metrics, resp, c.FailEmpty) + return writeAdSenseReportResult(ctx, u, plan.Account, plan.Dimensions, plan.Metrics, resp, c.FailEmpty, "raise --max (up to 100000) or narrow the report") } func applyAdSenseReportDateRange(call *adsenseapi.AccountsReportsGenerateCall, plan adSenseReportPlan) *adsenseapi.AccountsReportsGenerateCall { @@ -112,6 +112,7 @@ func writeAdSenseReportResult( metrics []string, resp *adsenseapi.ReportResult, failEmpty bool, + moreRowsHint string, ) error { if outfmt.IsJSON(ctx) { if err := outfmt.WriteJSON(ctx, stdoutWriter(ctx), map[string]any{ @@ -141,7 +142,7 @@ func writeAdSenseReportResult( } } if resp.TotalMatchedRows > int64(len(resp.Rows)) { - u.Err().Linef("# Showing %d of %d matched rows; raise --max (up to 100000) or narrow the report to see more", len(resp.Rows), resp.TotalMatchedRows) + u.Err().Linef("# Showing %d of %d matched rows; %s to see more", len(resp.Rows), resp.TotalMatchedRows, moreRowsHint) } if len(resp.Rows) == 0 { @@ -318,5 +319,5 @@ func (c *AdSenseReportsSavedQueryCmd) Run(ctx context.Context, flags *RootFlags) return err } - return writeAdSenseReportResult(ctx, u, name, nil, nil, resp, c.FailEmpty) + return writeAdSenseReportResult(ctx, u, name, nil, nil, resp, c.FailEmpty, "narrow the saved report, for example its date range") }