sdk-javascript icon indicating copy to clipboard operation
sdk-javascript copied to clipboard

SHOULD throw if time has an invalid value?

Open c-pius opened this issue 4 years ago • 5 comments

Describe the Bug If an invalid value for time is given, HTTP.toEvent silently defaults it to the current time in UTC.

Steps to Reproduce Use the following snippet:

const event = HTTP.toEvent({
  headers: {
    'Content-Type': 'application/json',
    'ce-id': '0815',
    'ce-specversion': '1.0',
    'ce-type': 'my.event.type',
    'ce-source': 'my.event.source',
    'ce-time': 'some invalid time string',
  },
  body: {}
})

Check the resulting event:

{
  //...
  id: '0815',
  specversion: '1.0',
  type: 'my.event.type',
  source: 'my.event.source',
  time: 2021-02-16T17:27:34+01:00 // defaulted date.now
}

Expected Behavior As with the other issues I opened regarding (silent) defaulting, I think HTTP.toEvent should not do this. I think it would be more appropriate to either fail fast on invalid input or take the original value with a subsequent event.validate() failing (maybe also thinking about strict mode as for instance in event.cloneWith).

In case of new CloudEvent(...) I agree that it makes sense to provide defaults.

Additional context Origin of this behavior seems to be here: https://github.com/cloudevents/sdk-javascript/blob/6be3b2751401e529fce6ccf8a406a057472c10a9/src/parsers.ts#L68

c-pius avatar Feb 17 '21 16:02 c-pius

This issue is stale because it has been open 30 days with no activity.

github-actions[bot] avatar Mar 20 '21 00:03 github-actions[bot]

In case of new CloudEvent(...) I agree that it makes sense to provide defaults.

I don't. I was suprised to find this. The field is optional - silently setting it is absolutely wrong imho and other SDKs don't do it (at least the Java one).

black-snow avatar Jan 26 '23 14:01 black-snow

This issue is stale because it has been open 30 days with no activity.

github-actions[bot] avatar Feb 26 '23 00:02 github-actions[bot]

not stale

black-snow avatar Feb 28 '23 11:02 black-snow

This issue is stale because it has been open 30 days with no activity.

github-actions[bot] avatar Apr 01 '23 00:04 github-actions[bot]