Skip to content

Add nice error when forgetting to add a sourceId for an event in aggregates #89

Description

@rhyslbw

This is a really easy mistake to make particularly for someone new. Currently if you omit the sourceId from an event, this is thrown:

TypeError: Cannot call method 'toString' of undefined
    at Asset.Space.eventSourcing.Aggregate.Aggregate._validateEvent (packages/space_event-sourcing/source/server/domain/aggregate.coffee:119:27)
    at Asset.Space.eventSourcing.Aggregate.Aggregate.record (packages/space_event-sourcing/source/server/domain/aggregate.coffee:79:6)
    at Asset._myCommandHandler (packages/myPackage/src/domain/myAggregate.js:64:17)
    at Asset.Space.eventSourcing.Aggregate.Aggregate.handle (packages/space_event-sourcing/source/server/domain/aggregate.coffee:95:27)
    at AssetRouter.<anonymous> (packages/space_event-sourcing/source/server/infrastructure/router.coffee:93:65)
    at AssetRouter.Space.eventSourcing.Router.Router._handleDomainErrors (packages/space_event-sourcing/source/server/infrastructure/router.coffee:102:17)
    at AssetRouter.Space.eventSourcing.Router.Router.messageHandler (packages/space_event-sourcing/source/server/infrastructure/router.coffee:93:26)
    at packages/space_event-sourcing/source/server/infrastructure/router.coffee:1:1
    at CommandBus.Space.messaging.CommandBus.CommandBus.send (packages/space_messaging/source/command_bus.coffee:25:7)
    at [object Object]:1:-11

-> ${eventType} in ${aggregate} is missing a sourceId. Add sourceId: this.getId() to this event

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions