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

looplab / eventhorizon / 12622512440

05 Jan 2025 07:58PM UTC coverage: 27.495% (-39.9%) from 67.361%
12622512440

Pull #419

github

web-flow
Merge b3c17d928 into ac3a97277
Pull Request #419: fix(ci): update to up/download-artifact v4

1769 of 6434 relevant lines covered (27.49%)

1.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/middleware/commandhandler/async/middleware.go
1
// Copyright (c) 2018 - The Event Horizon authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
package async
16

17
import (
18
        "context"
19
        "fmt"
20

21
        eh "github.com/looplab/eventhorizon"
22
)
23

24
// NewMiddleware returns a new async handling middleware that returns any errors
25
// on a error channel.
26
func NewMiddleware() (eh.CommandHandlerMiddleware, chan *Error) {
×
27
        errCh := make(chan *Error, 20)
×
28

×
29
        return eh.CommandHandlerMiddleware(func(h eh.CommandHandler) eh.CommandHandler {
×
30
                return eh.CommandHandlerFunc(func(ctx context.Context, cmd eh.Command) error {
×
31
                        go func() {
×
32
                                if err := h.HandleCommand(ctx, cmd); err != nil {
×
33
                                        // Always try to deliver errors.
×
34
                                        errCh <- &Error{err, ctx, cmd}
×
35
                                }
×
36
                        }()
37

38
                        return nil
×
39
                })
40
        }), errCh
41
}
42

43
// Error is an error containing the error and the command.
44
type Error struct {
45
        // Err is the error that happened when handling the command.
46
        Err error
47
        // Ctx is the context used when the error happened.
48
        Ctx context.Context
49
        // Command is the command handeled when the error happened.
50
        Command eh.Command
51
}
52

53
// Error implements the Error method of the error interface.
54
func (e *Error) Error() string {
×
55
        return fmt.Sprintf("%s (%s): %s", e.Command.CommandType(), e.Command.AggregateID(), e.Err.Error())
×
56
}
×
57

58
// Unwrap implements the errors.Unwrap method.
59
func (e *Error) Unwrap() error {
×
60
        return e.Err
×
61
}
×
62

63
// Cause implements the github.com/pkg/errors Unwrap method.
64
func (e *Error) Cause() error {
×
65
        return e.Unwrap()
×
66
}
×
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

© 2025 Coveralls, Inc