Repository navigation
fix: accept structured Kafka events without a time attribute - #680
Open
rida-ghreizy wants to merge 1 commit into
Open
rida-ghreizy wants to merge 1 commit into
rida-ghreizy wants to merge 1 commit into
Conversation
parseStructured always converted eventObj.time with new Date(...).toISOString(), which throws RangeError for events that omit the optional time attribute. Only normalize time when it is set. Signed-off-by: rida <ghreizyrida1@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Changes
parseStructuredin the Kafka binding (src/message/kafka/index.ts) always runs:timeis an optional attribute in the CloudEvents spec. When a structured Kafka message has notime,new Date(undefined)is an invalid date andtoISOString()throws, so the event can't be received at all:The HTTP binding accepts the same event.
This PR normalizes
timeonly when it is present. When it is absent, theCloudEventconstructor fills in the current time, as it does for HTTP.Description
New test in
test/integration/kafka_tests.ts: a structured Kafka message withouttimeconverts to a CloudEvent with the right id and data, and a validtime. Without the change it fails withRangeError: Invalid time value. With it, the full suite passes (npx mocha --require ts-node/register ./test/integration/**/*.ts: 235 passing), and ESLint is clean on the changed files.This doesn't overlap with #676 or #677, which change the HTTP binding and the
CloudEventtime validation.