nestjs / cqrs

A lightweight CQRS module for Nest framework (node.js) :balloon:
https://nestjs.com
MIT License
849 stars 150 forks source link

Cannot read properties of undefined (reading 'id') - possible breaking change for 8.0.1 #924

Closed gpanainte closed 2 years ago

gpanainte commented 2 years ago

Is there an existing issue for this?

Current behavior

I get the following error after upgrading to 8.0.1

Cannot read properties of undefined (reading 'id') => EventBus.defaultGetEventId [as getEventId] (/app/node_modules/@nestjs/cqrs/dist/helpers/default-get-event-id.js:7:72) => /app/node_modules/@nestjs/cqrs/dist/event-bus.js:81:75 => /app/node_modules/rxjs/dist/cjs/internal/operators/filter.js:9:120 => OperatorSubscriber._this._next (/app/node_modules/rxjs/dist/cjs/internal/operators/OperatorSubscriber.js:33:21) => OperatorSubscriber.Subscriber.next (/app/node_modules/rxjs/dist/cjs/internal/Subscriber.js:51:18) => /app/node_modules/rxjs/dist/cjs/internal/Subject.js:66:34 => Object.errorContext (/app/node_modules/rxjs/dist/cjs/internal/util/errorContext.js:22:9) => Subject.next (/app/node_modules/rxjs/dist/cjs/internal/Subject.js:58:24) => DefaultPubSub.publish (/app/node_modules/@nestjs/cqrs/dist/helpers/default-pubsub.js:9:23) => EventBus.publish (/app/node_modules/@nestjs/cqrs/dist/event-bus.js:43:32)

The change comes from the following commit https://github.com/nestjs/cqrs/commit/c593fea78129e7309f6f62f69739a54a9b8f577e

Minimum reproduction code

i'm working on a private repository

Steps to reproduce

No response

Expected behavior

If it is a breaking change the release notes should be updated with the migration steps

Package version

8.0.1

NestJS version

8.0.6

Node.js version

2022 v17.2.0

In which operating systems have you tested?

Other

No response

kamilmysliwiec commented 2 years ago

@MaciejSikorski can you look into that?

Sikora00 commented 2 years ago

@gpanainte is it an event without any handler?

gpanainte commented 2 years ago

@gpanainte is it an event without any handler?

hello @Sikora00,

yes we have events without any handler

sylvainar commented 2 years ago

Hello there,

I currently have this issue, however I do have a handler for this event.

export class CalculationGenericEvent implements AuditMessage {
  constructor(
    public readonly auditObject: AuditObject,
  ) {}
}

Then later in the code:


@EventsHandler([
  // ... all the things the audit handler is listening on

  // CALCULATIONS
  CalculationGenericEvent,
])
export class AuditMessageHandler implements IEventHandler<AuditMessage> {

I'm in 8.0.2. Did you publish the fix? Thanks.

Sikora00 commented 2 years ago

this has not yet been published, but it was a fix for a case when an event has no event handler. In your case, it's probably a mistake to provide events as an array @sylvainar. You can list them just with a comma.