diff --git a/packages/core/lib/messages/MetadataFiller.spec.ts b/packages/core/lib/messages/MetadataFiller.spec.ts index 43915b31..1ac102e0 100644 --- a/packages/core/lib/messages/MetadataFiller.spec.ts +++ b/packages/core/lib/messages/MetadataFiller.spec.ts @@ -5,7 +5,7 @@ const TEST_MESSAGE = { } const EVENT_DEFINITION = { - schemaVersion: '0.0.0' + schemaVersion: '0.0.0', } const SERVICE_ID = 'myServiceId' diff --git a/packages/core/lib/messages/MetadataFiller.ts b/packages/core/lib/messages/MetadataFiller.ts index 6b2cb57e..6215ae6c 100644 --- a/packages/core/lib/messages/MetadataFiller.ts +++ b/packages/core/lib/messages/MetadataFiller.ts @@ -54,9 +54,10 @@ export class CommonMetadataFiller implements MetadataFiller { return { producedBy: precedingMessageMetadata?.producedBy ?? this.serviceId, originatedFrom: precedingMessageMetadata?.originatedFrom ?? this.serviceId, - schemaVersion: precedingMessageMetadata?.schemaVersion - ?? eventDefinition.schemaVersion - ?? this.defaultVersion, + schemaVersion: + precedingMessageMetadata?.schemaVersion ?? + eventDefinition.schemaVersion ?? + this.defaultVersion, correlationId: precedingMessageMetadata?.correlationId ?? this.produceId(), } } diff --git a/packages/core/lib/queues/AbstractPublisherManager.ts b/packages/core/lib/queues/AbstractPublisherManager.ts index 5d55f232..1ea4288d 100644 --- a/packages/core/lib/queues/AbstractPublisherManager.ts +++ b/packages/core/lib/queues/AbstractPublisherManager.ts @@ -183,6 +183,11 @@ export abstract class AbstractPublisherManager< throw new Error(`No publisher for target ${eventTarget}`) } const messageDefinition = this.resolveMessageDefinition(eventTarget, message) + if (!messageDefinition) { + throw new Error( + `MessageDefinition for target "${eventTarget}" and type "${message.type}" not found in EventRegistry`, + ) + } const resolvedMessage = this.resolveMessage(messageDefinition, message, precedingEventMetadata) if (this.isAsync) { diff --git a/packages/sns/lib/sns/SnsPublisherManager.spec.ts b/packages/sns/lib/sns/SnsPublisherManager.spec.ts index 9b2e607c..7a42321e 100644 --- a/packages/sns/lib/sns/SnsPublisherManager.spec.ts +++ b/packages/sns/lib/sns/SnsPublisherManager.spec.ts @@ -96,6 +96,20 @@ describe('SnsPublisherManager', () => { }), ).rejects.toThrow('No publisher for target non-existing-topic') }) + + it('publish to an incorrect topic/message combination will throw error', async () => { + await expect( + publisherManager.publish(TestEvents.created.snsTopic, { + // @ts-expect-error Testing error scenario + type: 'dummy.type', + payload: { + newData: 'msg', + }, + }), + ).rejects.toThrow( + 'MessageDefinition for target "dummy" and type "dummy.type" not found in EventRegistry', + ) + }) }) describe('handlerSpy', () => {