Repository navigation
Fix football module: response body closed, invalid-league crash, unclear errors, and add test coverage - #2133
Merged
Seanstoppable merged 6 commits intoJul 26, 2026
Conversation
footballRequest() was closing resp.Body via defer before returning it, causing callers in widget.go to read an already-closed body and surface 'http2: response body closed' errors even with a valid API key. Also add a status code check so non-2xx responses (e.g. bad/ expired key, rate limiting) produce a clear error instead. Fixes wtfutil#1874 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Cover: response body remains readable after footballRequest returns, and non-2xx responses surface a clear error. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Previously an empty (but successfully fetched) standings/matches list showed a generic 'Error fetching ...' message, which was confusing -- it looked like a failure even though the request succeeded and simply had no data for the given range/competition. - GetStandings: 'No standings found for this competition' - GetMatches: 'No matches found between <from> and <to>' Also add widget_test.go with coverage for GetStandings/GetMatches: filtering by standingCount, scheduled/finished splitting, favorite team marking, and the new empty-result messages. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
NewWidget's error branch (invalid/unknown league code, e.g. 'SA' instead of 'PL') built a Widget without initializing the embedded view.TextWidget, leaving its embedded *view.Base nil. The very first render call needs widget.CommonSettings(), which dereferences that nil Base and crashes the whole app at startup with: panic: runtime error: invalid memory address or nil pointer dereference github.com/wtfutil/wtf/view.(*Base).CommonSettings(...) Fix: always initialize TextWidget via view.NewTextWidget in NewWidget, even on the invalid-league error path, so the widget can still render its error message instead of crashing. Add a regression test that constructs NewWidget with an invalid league code and calls CommonSettings()/content() to confirm it no longer panics. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Cover getLeague success/failure, markFavorite's home/away/no-favorite branches, content()'s happy path, and NewWidget's valid-league success path. Raises modules/football coverage from 13.1%% to 88.5%%. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Seanstoppable
deleted the
seanstoppable-issue-1874-football-api-calls-is-broken-8d9a88
branch
July 26, 2026 02:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes several bugs in the
footballmodule (issue #1874) and significantly improves its test coverage (13.1% → 88.5%).Bugs fixed
1. "http2: response body closed" on every request (the reported bug)
footballRequest()inmodules/football/client.goclosedresp.Bodyviadeferbefore returning the response to its caller:The deferred close ran when
footballRequestreturned, so by the timeGetStandings/GetMatchesinwidget.gocalledio.ReadAll(resp.Body), the body was already closed — producing the "response body closed" error (surfaced as an HTTP/2 stream error) even with a valid API key.widget.go's callers already correctlydefer resp.Body.Close()themselves after checking for errors, so the close inclient.gowas both wrong and redundant. Removed it.2. Silent/garbled errors on non-2xx API responses
Added a status-code check in
footballRequestso a bad/expired API key, rate limiting, etc. now returns a clearunexpected status code %d from football APIerror instead of a response whose body may be unusable.3. Crash on invalid/misspelled league code
NewWidget's error branch (e.g. league set toSAinstead ofPL) built aWidgetwithout initializing the embeddedview.TextWidget, leaving its embedded*view.Basenil. The very first render call needswidget.CommonSettings(), which dereferenced that nilBaseand crashed the whole app at startup:Fixed by always initializing
TextWidgetviaview.NewTextWidget, even on the invalid-league error path, so the widget renders its error message instead of crashing.4. Confusing "Error fetching..." message for empty (but successful) results
An empty standings/matches list previously showed a generic
Error fetching ...message, which looked like a failure even though the request succeeded and simply had no data for the given range/competition:GetStandings: now showsNo standings found for this competitionGetMatches: now showsNo matches found between <from> and <to>Test coverage
Added
modules/football/client_test.goandmodules/football/widget_test.gousinghttptestfake servers (no real API key needed) covering:footballRequestreturns (regression test for bug Add Reading List section #1)NewWidgetwith an invalid league code no longer panics (regression test for bug BambooHR improvements #3)NewWidget/getLeaguesuccess pathsGetStandingsfiltering bystandingCount, and the new empty-result messageGetMatchessplitting scheduled/finished matches, favorite-team marking (home/away/none), and the new empty-result messagecontent()happy pathmodules/footballcoverage: 13.1% → 88.5%.Testing
go build ./...✅go vet ./modules/football/...✅go test ./modules/football/...✅ (15 tests, all passing)Fixes #1874