• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sapcc / go-bits / 16415342294 / 1
31%
master: 31%

Build:
Build:
LAST BUILD BRANCH: fix-gomm
DEFAULT BRANCH: master
Ran 21 Jul 2025 11:10AM UTC
Files 56
Run time 2s
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

21 Jul 2025 11:08AM UTC coverage: 31.064% (-0.3%) from 31.389%
16415342294.1

Pull #238

github

majewsky
respondwith: add func CustomStatus

Over in Limes, there is lots of code duplication in the commitment API
that I want to reduce, but client error responses are making this
difficult. For example: (some args elided for brevity)

    var (
      resourceID                db.ProjectResourceID
      azResourceID              db.ProjectAZResourceID
      resourceAllowsCommitments bool
    )
    err := p.DB.QueryRow(findProjectAZResourceIDByLocationQuery, args...).
      Scan(&resourceID, &azResourceID, &resourceAllowsCommitments)
    if respondwith.ErrorText(w, err) {
      return
    }
    if !resourceAllowsCommitments {
      msg := fmt.Sprintf("resource %s/%s is not enabled in this project", args...)
      http.Error(w, msg, http.StatusUnprocessableEntity)
      return
    }

Splitting this into a helper function would require two error code
paths, one for generic server errors from the DB query failing, and
another for 422 errors from the !resourceAllowsCommitments check.
We would have something like:

    resourceID, azResourceID, ok := p.findProjectAZResourceIDByLocation(w, args)
    if !ok {
      return
    }

And the implementation of that helper function would need to take an
http.ResponseWriter. That's fine, I guess, and matches existing
precedent (see e.g. go-bits/gopherpolicy.Token.Require()). But I don't
like that all these helpers need to take a ResponseWriter and thus are
able to mess with the response in ways that they should not be allowed
to do.

This commit adds an alternate design where the helper function can
return an error that is annotated with a specific response status code
that respondwith.ErrorText() will use instead of the default of 500.
Pull Request #238: respondwith: add func CustomStatus

981 of 3158 relevant lines covered (31.06%)

3.38 hits per line

Source Files on job 16415342294.1
  • Tree
  • List 56
  • Changed 3
  • Source Changed 0
  • Coverage Changed 3
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Build 16415342294
  • e3e495bf on github
  • Prev Job for on respondwith-clienterror (#16350616886.1)
  • Delete
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc