Skip to content

Commit

Permalink
feat(subscriber): make sure we combine the errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfalkowski committed Dec 28, 2024
1 parent d6f45e7 commit 4682efb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2.1
jobs:
build:
docker:
- image: alexfalkowski/go:1.23
- image: alexfalkowski/go:1.3
- image: alexfalkowski/status:latest
command: server
environment:
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
resource_class: large
release:
docker:
- image: alexfalkowski/release:3.1
- image: alexfalkowski/release:3.4
working_directory: ~/go-health
steps:
- checkout
Expand Down
2 changes: 1 addition & 1 deletion server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func TestValidReadyChecker(t *testing.T) {
time.Sleep(wait)

Convey("Then I should have no error from the observer", func() {
So(ob.Error(), ShouldEqual, errNotReady)
So(ob.Error(), ShouldBeError)

checker.Ready()

Expand Down
24 changes: 17 additions & 7 deletions subscriber/errors.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
package subscriber

import (
"errors"
"fmt"
)

// Errors for observers.
type Errors map[string]error

// Error the first error from map.
// Error the combined errors as one.
func (e Errors) Error() error {
for _, err := range e {
errs := make([]error, len(e))
i := 0

for k, err := range e {
if err != nil {
return err
errs[i] = fmt.Errorf("%s: %w", k, err)
}

i++
}

return nil
return errors.Join(errs...)
}

// Errors is a copy.
func (e Errors) Errors() Errors {
errors := make(Errors)
errs := make(Errors, len(e))
for k, v := range e {
errors[k] = v
errs[k] = v
}

return errors
return errs
}

// Set the error at the name.
Expand Down

0 comments on commit 4682efb

Please sign in to comment.