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

stream: add track_caller to public APIs #4786

Merged
merged 1 commit into from
Jun 22, 2022

Conversation

hds
Copy link
Contributor

@hds hds commented Jun 22, 2022

Motivation

When a user of tokio calls a function that panics when misused (e.g. calling
Stream::chunks_timeout with max_size set to 0) then the user currently
sees the line number of the panic call inside tokio. It would be more informative
for the user to see the place where they called the panicking function.

It is still possible for the user to see the full stack trace by setting the
environment variable RUST_BACKLOG=1, so no useful information is
hidden.

This change is the third step in closing #4413 (starting with #4772), this change
is for the tokio-stream crate.

Solution

Functions that may panic can be annotated with #[track_caller] so that
in the event of a panic, the function where the user called the
panicking function is shown instead of the file and line within Tokio
source.

This change adds #[track_caller] to all the non-unstable public APIs
in tokio-stream (only chunks_timeout in StreamExt) where the
documentation describes how this function may panic due to incorrect
input.

A test has been included to cover the panic.

Refs: #4413

Functions that may panic can be annotated with `#[track_caller]` so that
in the event of a panic, the function where the user called the
panicking function is shown instead of the file and line within Tokio
source.

This change adds `#[track_caller]` to all the non-unstable public APIs
in tokio-stream (only `chunks_timeout` in `StreamExt`) where the
documentation describes how this function may panic due to incorrect
input.

A test has been included to cover the panic.

Refs: tokio-rs#4413
@Noah-Kennedy Noah-Kennedy enabled auto-merge (squash) June 22, 2022 17:18
@Noah-Kennedy Noah-Kennedy merged commit 485ca3e into tokio-rs:master Jun 22, 2022
@Darksonn Darksonn added the A-tokio-stream Area: The tokio-stream crate label Jun 23, 2022
@hds hds deleted the track-caller-stream branch July 21, 2022 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-stream Area: The tokio-stream crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants