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

fix(timestamp conversion): use timestamp_nanos_opt to avoid panics #979

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pront
Copy link
Collaborator

@pront pront commented Aug 6, 2024

closes: #978

@pront pront changed the title fix(timestamp conversion): use timestamp_nanos_opt to avoid panics wh… fix(timestamp conversion): use timestamp_nanos_opt to avoid panics Aug 6, 2024
@pront pront requested a review from jszwedko August 6, 2024 20:47
@pront pront marked this pull request as ready for review August 6, 2024 20:47
Copy link
Member

@jszwedko jszwedko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a breaking change, no? I think the fallibility of these functions needs to be updated. We'll also want to document how to migrate.

Nit: I think we could use clippy to disallow calls to timestamp_nanos() to avoid accidentally introducing a panic in the future. See https://rust-lang.github.io/rust-clippy/master/#/disallowed_method

@@ -0,0 +1 @@
Replaced all usages of `timestamp_nanos` with `timestamp_nanos_opt` to avoid panics when the timestamp is out of range.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Replaced all usages of `timestamp_nanos` with `timestamp_nanos_opt` to avoid panics when the timestamp is out of range.
`to_unix_timestamp`, `to_float`, and `uuid_v7` can now return an error if the supplied timestamp is unrepresentable as a nanosecond timestamp. Previously the function calls would panic.

The changelogs should have the user in mind as the audience. I also think this is a breaking change, no? We'll want to document how to migrate.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, marking this PR as a draft for now. I will try to find some propose a migration plan. I need to refresh my memory on the deprecation process as well.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We provide linters for such changes. In this way we have eliminated the deprecation of to_timestamp.
I think there is no problem in this case, because the vector during validation will report that to_unix_timestamp returns an error, and this is not handled

@pront pront marked this pull request as draft August 6, 2024 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vector stops with panic at to_unix_timestamp format:nanoseconds VRL function
3 participants