Skip to content

Fix errcheck violation in RSS feed handler#22

Merged
NickFoden merged 4 commits intolinksfrom
copilot/fix-writer-error-check
Mar 2, 2026
Merged

Fix errcheck violation in RSS feed handler#22
NickFoden merged 4 commits intolinksfrom
copilot/fix-writer-error-check

Conversation

Copy link
Contributor

Copilot AI commented Mar 1, 2026

The Feed handler in internal/handlers/blog.go had two unchecked w.Write() calls, violating errcheck linting rules.

Changes

  • Check error return from w.Write() in the RSS feed handler
  • Combine XML header and data into single write operation to prevent partial responses
  • Use generic error message instead of exposing err.Error() to clients
  • Pre-allocate output buffer with exact capacity to avoid reallocation

Before

w.Write([]byte(xml.Header))
w.Write(data)

After

output := make([]byte, 0, len(xml.Header)+len(data))
output = append(output, []byte(xml.Header)...)
output = append(output, data...)
if _, err := w.Write(output); err != nil {
    // Cannot send error response after w.Write has been called
    return
}

Single write ensures atomicity—either the complete RSS feed is sent or nothing is written to the response body.

Original prompt

Pull Request: #21

Error: internal/handlers/blog.go:168:9: Error return value of w.Write is not checked (errcheck)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits March 1, 2026 22:42
Co-authored-by: NickFoden <8321838+NickFoden@users.noreply.github.com>
…ssages

Co-authored-by: NickFoden <8321838+NickFoden@users.noreply.github.com>
Co-authored-by: NickFoden <8321838+NickFoden@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error return value of w.Write not checked Fix errcheck violation in RSS feed handler Mar 1, 2026
@NickFoden NickFoden marked this pull request as ready for review March 2, 2026 02:01
@NickFoden NickFoden merged commit 5989d8d into links Mar 2, 2026
@NickFoden NickFoden deleted the copilot/fix-writer-error-check branch March 2, 2026 02:02
NickFoden added a commit that referenced this pull request Mar 2, 2026
* feat(quick-2): add About and GitHub links to site footer

- Add footer_nav with /about and https://github.com/NickFoden links
- GitHub link opens in new tab with rel="noopener noreferrer"
- Style footer nav centered with flex layout and underline on hover

* docs(quick-2): complete add-about-github-links-to-footer plan

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs(quick-2): Add about and github links to site footer

* Tweak about

* feat: update footer nav with GitHub icon, Feed link, and Sixtyfour font

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* docs(quick-3): create plan for RSS feed at /feed.xml

* feat(quick-3): add RSS feed handler to BlogHandler

- Define rssItem, rssChannel, rssFeed structs using encoding/xml
- Add Feed method that generates RSS 2.0 XML from h.posts
- Set Content-Type to application/rss+xml; charset=utf-8
- Use time.RFC1123Z for pubDate and lastBuildDate

* feat(quick-3): register /feed.xml route in main.go

- Add r.Get("/feed.xml", blogHandler.Feed) alongside page routes
- Activates the footer link that previously had no matching route

* docs(quick-3): complete RSS feed plan summary and state update

- 3-SUMMARY.md documents feed handler and route implementation
- STATE.md updated with quick task 3 completion entry

* Add the www

* abc

* Fix errcheck violation in RSS feed handler (#22)

* Initial plan

* Fix errcheck linting error by checking w.Write return values

Co-authored-by: NickFoden <8321838+NickFoden@users.noreply.github.com>

* Address code review feedback: combine writes and use generic error messages

Co-authored-by: NickFoden <8321838+NickFoden@users.noreply.github.com>

* Optimize slice allocation with pre-sized capacity

Co-authored-by: NickFoden <8321838+NickFoden@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NickFoden <8321838+NickFoden@users.noreply.github.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NickFoden <8321838+NickFoden@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants