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

sapcc / go-bits / 16403482368
31%
master: 31%

Build:
Build:
LAST BUILD BRANCH: fix-gomm
DEFAULT BRANCH: master
Ran 20 Jul 2025 07:33PM UTC
Jobs 1
Files 56
Run time 1min
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

20 Jul 2025 07:23PM UTC coverage: 31.127% (-0.3%) from 31.389%
16403482368

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

0 of 25 new or added lines in 2 files covered. (0.0%)

3 existing lines in 2 files now uncovered.

983 of 3158 relevant lines covered (31.13%)

3.38 hits per line

New Missed Lines in Diff

Lines Coverage ∆ File
9
11.76
-1.57% respondwith/pkg.go
16
0.0
respondwith/error.go

Uncovered Existing Lines

Lines Coverage ∆ File
1
11.76
-1.57% respondwith/pkg.go
2
74.19
-2.15% jobloop/producer_consumer.go
Jobs
ID Job ID Ran Files Coverage
1 16403482368.1 20 Jul 2025 07:33PM UTC 56
31.13
GitHub Action Run
Source Files on build 16403482368
  • Tree
  • List 56
  • Changed 2
  • Source Changed 0
  • Coverage Changed 2
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Repo
  • Pull Request #238
  • PR Base - master (#16350616886)
  • 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