tracing
Fix global LogTracer installation by using InitError enum instead of Boxed errors
#406
Merged

Fix global LogTracer installation by using InitError enum instead of Boxed errors #406

emschwartz
emschwartz5 years ago (edited 5 years ago)

🤦‍♂️

Motivation

I thought the boxing errors solution implemented in #400 was equivalent to the enum solution in emschwartz@f22bae5, but the current master doesn't actually work to install the global LogTracer.

I can't figure out why the current cargo features don't end up turning on this line, but I confirmed with the log example in 4511325 that it's not currently working.

Solution

Using an enum for the two types of errors instead of boxing them solves the problem.

emschwartz subscriber: use InitError enum instead of Box
d1e3d8ce
emschwartz examples: log compatibility
4511325b
hawkw
hawkw5 years ago

@emschwartz I don't think

#[cfg(feature = "tracing-log/std")]

is valid — I think if we want to have a feature gate for enabling the std feature on tracing-log, we need to add our own feature flag for it.

Or, I think, we should just always enable tracing-log/std in the subscriber crate's Cargo.toml; the subscriber crate already requires the standard library and doesn't support no-std currently. That's what I was trying to say in #400 (comment), but this may have not been clear, sorry!

emschwartz
emschwartz5 years ago

@hawkw I tried to get the impl Error... return type to work but haven't been able to figure out how.

tracing-subscriber currently includes the std feature for tracing-log. However, changing this line to #[cfg(feature = "tracing-log")] produces this error:

error[E0277]: `?` couldn't convert the error to `std::boxed::Box<tracing_core::dispatcher::SetGlobalDefaultError>`
   --> tracing-subscriber/src/fmt/mod.rs:453:57
    |
453 |         tracing_log::LogTracer::init().map_err(Box::new)?;
    |                                                         ^ the trait `std::convert::From<std::boxed::Box<log::SetLoggerError>>` is not implemented for `std::boxed::Box<tracing_core::dispatcher::SetGlobalDefaultError>`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following implementations were found:
              <std::boxed::Box<(dyn std::error::Error + 'a)> as std::convert::From<E>>
              <std::boxed::Box<(dyn std::error::Error + 'static)> as std::convert::From<&str>>
              <std::boxed::Box<(dyn std::error::Error + 'static)> as std::convert::From<std::borrow::Cow<'a, str>>>
              <std::boxed::Box<(dyn std::error::Error + 'static)> as std::convert::From<std::string::String>>
            and 16 others
    = note: required by `std::convert::From::from`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: Could not compile `tracing-subscriber`.

To learn more, run the command again with --verbose.

I tried casting both to Box<Error>s but then get errors saying that it can't be sent between threads or isn't sized.

If you know how to quickly solve this, feel free to edit the PR. I'm pretty stumped though so I'd opt to just use the enum.

hawkw fix dependencies
66b9fdbd
hawkw fix boxed errors
b5081b49
hawkw
hawkw5 years ago

@emschwartz I went ahead and fixed the boxed errors, I hope that's okay! I wanted to be able to go ahead and merge this so we can get a v0.1.6 release published.

hawkw cargo fmt
ecc7a680
emschwartz
emschwartz commented on 2019-10-28
tracing-log/src/log_tracer.rs
2828//! [ignore]: struct.Builder.html#method.ignore_crate
2929use crate::{format_trace, AsTrace};
3030use log;
31
pub use log::SetLoggerError;
emschwartz5 years ago

If the error is boxed, this type doesn't need to be made public

hawkw5 years ago

the errors in tracing-log are not boxed (which was the case before, I think — I'm surprised that wasn't a problem in the past)

emschwartz
emschwartz5 years ago

@hawkw Sounds good, thanks for doing that!

hawkw
hawkw approved these changes on 2019-10-28
hawkw hawkw merged 5dc2b158 into master 5 years ago
emschwartz emschwartz deleted the es-fix-subscriber branch 5 years ago

Login to write a write a comment.

Login via GitHub

Reviewers
Assignees
No one assigned
Labels
Milestone