-
Notifications
You must be signed in to change notification settings - Fork 110
Support any data to be passed by attach (replace attach_message)
#609
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
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
990aba5
Add `provide` method
TimDiekmann 1559d74
Fix intra-doc links
TimDiekmann ad30fe4
Fix miri
TimDiekmann 4fb53b9
Rename `FutureWithProvided` to `FutureWithProvidedRef`
TimDiekmann ff63749
Combine `attach_message` and `provide`
TimDiekmann a9a4b15
Apply changes to hEngine
TimDiekmann 55a8db8
Test the new feature
TimDiekmann 610c0cf
Improve documentation on `FrameObject`
TimDiekmann 4d18139
Fix downcasting
TimDiekmann b72ba37
Remove `SingleProvider`
TimDiekmann 74b6b3b
Merge branch 'main' into td/provide-directly
TimDiekmann 8bdd064
Rework attaching and context
TimDiekmann 18d2b9c
Update packages/engine/lib/error/src/frame.rs
TimDiekmann e9473b5
Update packages/engine/lib/error/src/frame.rs
TimDiekmann 6fc1721
Update packages/engine/lib/error/src/report.rs
TimDiekmann 31a543b
Update packages/engine/lib/error/src/result.rs
TimDiekmann 725a303
Simplify `Frame` implementation by removing `Unerased`
TimDiekmann 3277be6
Clean up code
TimDiekmann 35ecbb1
Clarify documentation on `Frame`
TimDiekmann 028ccfe
Clarify documentation on trace capturing
TimDiekmann b2bc61e
Mention the feature flags section on [`Report`]
TimDiekmann 7900847
Fix tests
TimDiekmann f0280b9
Clarified `Frame` docs more
TimDiekmann e8dbd74
Clarified `Frame` docs more
TimDiekmann ea43ccc
Fix clippy on no-default-features
TimDiekmann 069bb52
Clarify retrieving of the backtrace/spantrace
TimDiekmann 7e5d08c
Add note on backtrace and spantrace to `Report::new`
TimDiekmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| use core::fmt; | ||
|
|
||
| #[cfg(nightly)] | ||
| use crate::provider::Demand; | ||
| #[cfg(all(nightly, any(feature = "std", feature = "spantrace")))] | ||
| use crate::provider::Provider; | ||
| use crate::Report; | ||
|
|
||
| /// Defines the current context of a [`Report`]. | ||
| /// | ||
| /// When in a `std` environment, every [`Error`] is a valid `Context`. This trait is not limited to | ||
| /// [`Error`]s and can also be manually implemented for custom objects. | ||
| /// | ||
| /// [`Error`]: std::error::Error | ||
| /// | ||
| /// ## Example | ||
| /// | ||
| /// Used for creating a [`Report`] or for switching the [`Report`]'s context: | ||
| /// | ||
| /// ```rust | ||
| /// # #![cfg_attr(any(not(feature = "std"), miri), allow(unused_imports))] | ||
| /// use std::{fmt, fs, io}; | ||
| /// | ||
| /// use error::{Context, IntoReport, Result, ResultExt}; | ||
| /// | ||
| /// # type Config = (); | ||
| /// #[derive(Debug)] | ||
| /// pub enum ConfigError { | ||
| /// ParseError, | ||
| /// } | ||
| /// | ||
| /// impl fmt::Display for ConfigError { | ||
| /// # #[allow(unused_variables)] | ||
| /// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| /// # const _: &str = stringify! { | ||
| /// ... | ||
| /// # }; Ok(()) | ||
| /// } | ||
| /// } | ||
| /// | ||
| /// // In this scenario, `Error` is not implemented for `ConfigError` for some reason, so implement | ||
| /// // `Context` manually. | ||
| /// impl Context for ConfigError {} | ||
| /// | ||
| /// # #[cfg(any(not(feature = "std"), miri))] | ||
| /// # pub fn read_file(_: &str) -> Result<String, ConfigError> { error::bail!(ConfigError::ParseError) } | ||
| /// # #[cfg(all(feature = "std", not(miri)))] | ||
| /// pub fn read_file(path: &str) -> Result<String, io::Error> { | ||
| /// // Creates a `Report` from `io::Error`, the current context is `io::Error` | ||
| /// fs::read_to_string(path).report() | ||
| /// } | ||
| /// | ||
| /// pub fn parse_config(path: &str) -> Result<Config, ConfigError> { | ||
| /// // The return type of `parse_config` requires another context. By calling `change_context` | ||
| /// // the context may be changed. | ||
| /// read_file(path).change_context(ConfigError::ParseError)?; | ||
| /// | ||
| /// # const _: &str = stringify! { | ||
| /// ... | ||
| /// # }; Ok(()) | ||
| /// } | ||
| /// # let err = parse_config("invalid-path").unwrap_err(); | ||
| /// # #[cfg(all(feature = "std", not(miri)))] | ||
| /// # assert!(err.contains::<io::Error>()); | ||
| /// # assert!(err.contains::<ConfigError>()); | ||
| /// # assert_eq!(err.frames().count(), 2); | ||
| /// ``` | ||
| pub trait Context: fmt::Display + fmt::Debug + Send + Sync + 'static { | ||
| /// Provide values which can then be requested by [`Report`]. | ||
| #[cfg(nightly)] | ||
| #[allow(unused_variables)] | ||
| fn provide<'a>(&'a self, demand: &mut Demand<'a>) {} | ||
| } | ||
|
|
||
| impl<C> From<C> for Report<C> | ||
| where | ||
| C: Context, | ||
| { | ||
| #[track_caller] | ||
| #[inline] | ||
| fn from(context: C) -> Self { | ||
| Self::new(context) | ||
| } | ||
| } | ||
|
|
||
| /// Turns a [`Context`] into a temporary [`Provider`]. | ||
| /// | ||
| /// To enable the usage of the [`Provider`] trait without implementing [`Provider`] for [`Context`] | ||
| /// this function wraps a reference to a [`Context`] inside of a [`Provider`] | ||
| // We can't implement `Provider` on Context as `Error` will implement `Provider` and `Context` will | ||
| // be implemented on `Error`. For `request`ing a type from `Context`, we need a `Provider` | ||
| // implementation however. | ||
| #[cfg(all(nightly, any(feature = "std", feature = "spantrace")))] | ||
| pub fn temporary_provider(context: &impl Context) -> impl Provider + '_ { | ||
Alfred-Mountfield marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| struct ProviderImpl<'a, C>(&'a C); | ||
| impl<C: Context> Provider for ProviderImpl<'_, C> { | ||
| fn provide<'a>(&'a self, demand: &mut Demand<'a>) { | ||
| self.0.provide(demand); | ||
| } | ||
| } | ||
| ProviderImpl(context) | ||
| } | ||
|
|
||
| #[cfg(feature = "std")] | ||
| impl<C: std::error::Error + Send + Sync + 'static> Context for C { | ||
| #[cfg(nightly)] | ||
| fn provide<'a>(&'a self, demand: &mut Demand<'a>) { | ||
| if let Some(backtrace) = self.backtrace() { | ||
| demand.provide_ref(backtrace); | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.