Skip to content

Commit

Permalink
fix: JOIN-32425 show warning when undefined is inside PreserveNull in…
Browse files Browse the repository at this point in the history
… publisher, and set null on PreserveNull fields in subscriber
  • Loading branch information
eugene-taran committed Jun 14, 2023
1 parent 6967ee1 commit 54756b7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packages/pubsub/src/Publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class Publisher<T = unknown> {
private logWarnIfMessageViolatesSchema(data: T): void {
if (this.writerAvroType) {
if (!this.writerAvroType.isValid(data)) {
this.logger?.warn('Message violates writer avro schema', { payload: data, metadata: this.avroMessageMetadata })
this.logger?.warn(`[schema-violation] [${this.topicName}] Message violates writer avro schema`, { payload: data, metadata: this.avroMessageMetadata })
}
}
}
Expand Down Expand Up @@ -161,9 +161,9 @@ export class Publisher<T = unknown> {
// for now we are checking that avro is enabled before calling sendAvroMessage
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
if (!this.writerAvroType!.isValid(data)) {
this.logger?.error('Invalid payload for the specified writer schema, please check that the schema is correct ' +
'and payload can be encoded with it', {payload: data, schemaMetadata: this.avroMessageMetadata})
throw new Error(`Can't encode the avro message for the topic ${this.topicName}`)
this.logger?.error(`[${this.topicName}] Invalid payload for the specified writer schema, please check that the schema is correct ' +
'and payload can be encoded with it`, {payload: data, schemaMetadata: this.avroMessageMetadata})
throw new Error(`[${this.topicName}] Can't encode the avro message for the topic`)
}
if (this.avroMessageMetadata && this.avroMessageMetadata['join_preserve_null']) {
logWarnWhenUndefinedInNullPreserveFields(data, this.avroMessageMetadata['join_preserve_null'], this.logger)
Expand Down
2 changes: 1 addition & 1 deletion packages/pubsub/src/__tests__/Subscriber.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ describe('Subscriber', () => {
})

it('receives avro parsed data', async () => {
topicMock.exists.mockResolvedValue([false])
topicMock.exists.mockResolvedValue([true])
subscriptionMock.exists.mockResolvedValue([true])
topicMock.getMetadata.mockResolvedValue([{'schemaSettings': {'schema': 'mock-schema'}}])
schemaClientMock.getSchema.mockResolvedValue([{definition: JSON.stringify(SCHEMA_DEFINITION_EXAMPLE)}])
Expand Down

0 comments on commit 54756b7

Please sign in to comment.