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

task: add track_caller to public APIs #4848

Merged
merged 1 commit into from Jul 20, 2022

Commits on Jul 20, 2022

  1. task: add track_caller to public APIs

    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 public APIs in the task
    module of the tokio crate where the documentation describes how the
    function may panic due to incorrect context or inputs.
    
    In cases where `#[track_caller]` does not work, it has been left out.
    For example, it currently does not work on async functions, blocks, or
    closures. So any call stack that passes through one of these before
    reaching the actual panic is not able to show the calling site outside
    of tokio as the panic location.
    
    The following functions have call stacks that pass through closures:
    * `task::block_in_place`
    * `task::local::spawn_local`
    
    Tests are included to cover each potentially panicking function.
    
    The following functions already had `#[track_caller]` applied everywhere
    it was needed and only tests have been added:
    * `task::spawn`
    * `task::LocalKey::sync_scope`
    
    Refs: tokio-rs#4413
    hds committed Jul 20, 2022
    Copy the full SHA
    5568a16 View commit details
    Browse the repository at this point in the history