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

add track_caller to public APIs (#4413) #4772

Merged
merged 6 commits into from Jun 22, 2022
Merged

Commits on Jun 16, 2022

  1. add track_caller to public APIs (tokio-rs#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 core where the documentation describes how the function may panic
    due to incorrect context or inputs.  Since each internal function needs
    to be annotated down to the actual panic, it makes sense to start in
    Tokio core functionality.
    
    Tests are needed to ensure that all the annotations remain in place in
    case internal refactoring occurs.
    
    The test installs a panic hook to extract the file location from the
    `PanicInfo` struct and clone it up to the outer scope to check that the
    panic was indeed reported from within the test file.  The downside to
    this approach is that the panic hook is global while set and so we need
    a lot of extra functionality to effectively serialize the tests so that
    only a single panic can occur at a time.
    
    The annotation of `block_on` was removed as it did not work. It appears
    to be impossible to correctly chain track caller when the call stack to
    the panic passes through clojures, as the track caller annotation can
    only be applied to functions. Also, the panic message itself is very
    descriptive.
    hds committed Jun 16, 2022
    Copy the full SHA
    8e1cf59 View commit details
    Browse the repository at this point in the history

Commits on Jun 17, 2022

  1. fix race condition and remove lazy_static

    Based on feedback (thank-you!), the timer in the into_panic test has
    been replaced with `futures::future::pending()` and the lazy_static
    dev-dependency has been removed and replaced with `const_mutex` from
    `parking_lot`.
    
    Additionally, the panic catching has been reworked a little bit to set
    and unset the panic hook around the part of the test where the panic is
    expected. This fixes the issue that the normal test output for a failed
    test was being eaten up by the custom panic hook.
    hds committed Jun 17, 2022
    Copy the full SHA
    cddbcb9 View commit details
    Browse the repository at this point in the history
  2. add await to future::pending

    Caught by the clippy lint.
    hds committed Jun 17, 2022
    Copy the full SHA
    0196c31 View commit details
    Browse the repository at this point in the history
  3. use future::pending directly in tokio::spawn

    As suggested in review, instead of wrapping it in
    async+await.
    
    Co-authored-by: Alice Ryhl <aliceryhl@google.com>
    hds and Darksonn committed Jun 17, 2022
    Copy the full SHA
    aaf73a8 View commit details
    Browse the repository at this point in the history

Commits on Jun 21, 2022

  1. Remove "test_" prefix from test functions

    I noticed that no other tests in tokio are prefixed with
    `test_`, so I removed it from the new ones added.
    hds committed Jun 21, 2022
    Copy the full SHA
    f406d0e View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    e1fe84a View commit details
    Browse the repository at this point in the history