Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add panicx package. #176

Merged
merged 2 commits into from
Nov 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ migrate tests from prior versions.
- Add `TimeAdjuster` interface, for use with `AdvanceTime()`
- Add `engine.EnableHandler()`
- Add `Test.EnableHandlers()` and `DisableHandlers()`
- Add `panicx.Location`
- **[BC]** Add `TestingT.Failed()`, `Fatal()` and `Helper()` methods

### Changed
Expand All @@ -37,6 +38,7 @@ migrate tests from prior versions.
- **[BC]** `engine.New()` and `MustNew()` now accept `configkit.RichApplication` (previously `dogma.Application`)
- **[BC]** Rename `WithStartTime()` to `StartTimeAt()`
- **[BC]** Rename `WithOperationOptions()` to `WithUnsafeOperationOptions()`
- **[BC]** Move `controller.ConvertUnexpectedMessagePanic()` to `panicx.EnrichUnexpectedMessage()`

### Removed

Expand Down
8 changes: 4 additions & 4 deletions engine/controller/aggregate/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (

"github.com/dogmatiq/configkit"
"github.com/dogmatiq/configkit/message"
"github.com/dogmatiq/testkit/engine/controller"
"github.com/dogmatiq/testkit/engine/envelope"
"github.com/dogmatiq/testkit/engine/fact"
"github.com/dogmatiq/testkit/engine/panicx"
)

// Controller is an implementation of engine.Controller for
Expand Down Expand Up @@ -46,7 +46,7 @@ func (c *Controller) Handle(
env.Role.MustBe(message.CommandRole)

var id string
controller.ConvertUnexpectedMessagePanic(
panicx.EnrichUnexpectedMessage(
c.Config,
"AggregateMessageHandler",
"RouteCommandToInstance",
Expand Down Expand Up @@ -75,7 +75,7 @@ func (c *Controller) Handle(

if exists {
for _, env := range history {
controller.ConvertUnexpectedMessagePanic(
panicx.EnrichUnexpectedMessage(
c.Config,
"AggregateRoot",
"ApplyEvent",
Expand Down Expand Up @@ -111,7 +111,7 @@ func (c *Controller) Handle(
command: env,
}

controller.ConvertUnexpectedMessagePanic(
panicx.EnrichUnexpectedMessage(
c.Config,
"AggregateMessageHandler",
"HandleCommand",
Expand Down
4 changes: 2 additions & 2 deletions engine/controller/aggregate/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

"github.com/dogmatiq/configkit"
"github.com/dogmatiq/dogma"
"github.com/dogmatiq/testkit/engine/controller"
"github.com/dogmatiq/testkit/engine/envelope"
"github.com/dogmatiq/testkit/engine/fact"
"github.com/dogmatiq/testkit/engine/panicx"
)

// scope is an implementation of dogma.AggregateCommandScope.
Expand Down Expand Up @@ -72,7 +72,7 @@ func (s *scope) RecordEvent(m dogma.Message) {
s.exists = true
}

controller.ConvertUnexpectedMessagePanic(
panicx.EnrichUnexpectedMessage(
s.config,
"AggregateRoot",
"ApplyEvent",
Expand Down
6 changes: 3 additions & 3 deletions engine/controller/integration/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

"github.com/dogmatiq/configkit"
"github.com/dogmatiq/configkit/message"
"github.com/dogmatiq/testkit/engine/controller"
"github.com/dogmatiq/testkit/engine/envelope"
"github.com/dogmatiq/testkit/engine/fact"
"github.com/dogmatiq/testkit/engine/panicx"
)

// Controller is an implementation of engine.Controller for
Expand Down Expand Up @@ -43,7 +43,7 @@ func (c *Controller) Handle(
env.Role.MustBe(message.CommandRole)

var t time.Duration
controller.ConvertUnexpectedMessagePanic(
panicx.EnrichUnexpectedMessage(
c.Config,
"IntegrationMessageHandler",
"TimeoutHint",
Expand All @@ -68,7 +68,7 @@ func (c *Controller) Handle(
}

var err error
controller.ConvertUnexpectedMessagePanic(
panicx.EnrichUnexpectedMessage(
c.Config,
"IntegrationMessageHandler",
"HandleCommand",
Expand Down
96 changes: 0 additions & 96 deletions engine/controller/panic.go

This file was deleted.

8 changes: 4 additions & 4 deletions engine/controller/process/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/dogmatiq/configkit"
"github.com/dogmatiq/configkit/message"
"github.com/dogmatiq/dogma"
"github.com/dogmatiq/testkit/engine/controller"
"github.com/dogmatiq/testkit/engine/envelope"
"github.com/dogmatiq/testkit/engine/fact"
"github.com/dogmatiq/testkit/engine/panicx"
)

// Controller is an implementation of engine.Controller for
Expand Down Expand Up @@ -66,7 +66,7 @@ func (c *Controller) Handle(
env.Role.MustBe(message.EventRole, message.TimeoutRole)

var t time.Duration
controller.ConvertUnexpectedMessagePanic(
panicx.EnrichUnexpectedMessage(
c.Config,
"ProcessMessageHandler",
"TimeoutHint",
Expand Down Expand Up @@ -169,7 +169,7 @@ func (c *Controller) routeEvent(
ok bool
err error
)
controller.ConvertUnexpectedMessagePanic(
panicx.EnrichUnexpectedMessage(
c.Config,
"ProcessMessageHandler",
"RouteEventToInstance",
Expand Down Expand Up @@ -230,7 +230,7 @@ func (c *Controller) handle(ctx context.Context, s *scope) error {
}

var err error
controller.ConvertUnexpectedMessagePanic(
panicx.EnrichUnexpectedMessage(
c.Config,
"ProcessMessageHandler",
method,
Expand Down
6 changes: 3 additions & 3 deletions engine/controller/projection/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

"github.com/dogmatiq/configkit"
"github.com/dogmatiq/configkit/message"
"github.com/dogmatiq/testkit/engine/controller"
"github.com/dogmatiq/testkit/engine/envelope"
"github.com/dogmatiq/testkit/engine/fact"
"github.com/dogmatiq/testkit/engine/panicx"
)

// CompactInterval is how frequently projections should be compacted.
Expand Down Expand Up @@ -76,7 +76,7 @@ func (c *Controller) Handle(
handler := c.Config.Handler()

var t time.Duration
controller.ConvertUnexpectedMessagePanic(
panicx.EnrichUnexpectedMessage(
c.Config,
"ProjectionMessageHandler",
"TimeoutHint",
Expand Down Expand Up @@ -145,7 +145,7 @@ func (c *Controller) Handle(
}

var ok bool
controller.ConvertUnexpectedMessagePanic(
panicx.EnrichUnexpectedMessage(
c.Config,
"ProjectionMessageHandler",
"HandleEvent",
Expand Down
3 changes: 3 additions & 0 deletions engine/panicx/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Package panicx contains utilities for providing meaningful contexts to panics
// that occur with the engine.
package panicx
15 changes: 15 additions & 0 deletions engine/panicx/ginkgo_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package panicx_test

import (
"reflect"
"testing"

"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
)

func TestSuite(t *testing.T) {
type tag struct{}
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, reflect.TypeOf(tag{}).PkgPath())
}
Loading