Skip to content

Commit

Permalink
Return concrete error type (#3360)
Browse files Browse the repository at this point in the history
Go development practices favors returning concrete types over interfaces, so the users don't have to force cast the return value to the concrete type and the APIs self document the returned error type.
  • Loading branch information
rakyll authored Jun 15, 2021
1 parent e10e703 commit f763d8b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions receiver/scrapererror/partialscrapeerror.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ package scrapererror

import "errors"

// PartialScrapeError can be used to signalize that a subset of metrics were failed
// to be scraped
// PartialScrapeError is an error to represent
// that a subset of metrics were failed to be scraped.
type PartialScrapeError struct {
error
Failed int
}

// NewPartialScrapeError creates PartialScrapeError for failed metrics.
// Use this error type only when a subset of data was failed to be scraped.
func NewPartialScrapeError(err error, failed int) error {
func NewPartialScrapeError(err error, failed int) PartialScrapeError {
return PartialScrapeError{
error: err,
Failed: failed,
Expand Down
2 changes: 1 addition & 1 deletion receiver/scrapererror/partialscrapeerror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestPartialScrapeError(t *testing.T) {
err := fmt.Errorf("some error")
partialErr := NewPartialScrapeError(err, failed)
assert.Equal(t, err.Error(), partialErr.Error())
assert.Equal(t, failed, partialErr.(PartialScrapeError).Failed)
assert.Equal(t, failed, partialErr.Failed)
}

func TestIsPartialScrapeError(t *testing.T) {
Expand Down

0 comments on commit f763d8b

Please sign in to comment.