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

Better error for "event not found" #171

Merged
merged 1 commit into from
Jun 19, 2024
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: 1 addition & 1 deletion packages/core/lib/messages/MetadataFiller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const TEST_MESSAGE = {
}

const EVENT_DEFINITION = {
schemaVersion: '0.0.0'
schemaVersion: '0.0.0',
}

const SERVICE_ID = 'myServiceId'
Expand Down
7 changes: 4 additions & 3 deletions packages/core/lib/messages/MetadataFiller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
Expand Down
5 changes: 5 additions & 0 deletions packages/core/lib/queues/AbstractPublisherManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions packages/sns/lib/sns/SnsPublisherManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Loading