Comments (7)
For the "source" of the error (with compatibility to std::err::Error
) we could either only take the left hand side, or linearize the resulting graph through topological sorting.
from hash.
Just as a reference, the topological sorting using DFS of the graph shown above would result in the following:
flowchart BT;
a{{std::io::Error}} --> b{{crate1::Error}}
b --> c[crate2::Context2]
c --> d[crate3::Context2]
d --> e{{std::io::Error}}
e --> f[crate2::Context]
f --> g[crate3::Context]
g --> h[crate4::Context]
from hash.
Hi @indietyp and thanks for filing this!
Generally, Pull Request are highly appreciated!
This is a pretty good scenario and we haven't thought about this yet. However, it's possible to attach any data to a Report
, even other reports like:
let report_a = Report::new(...);
let report_b = Report::new(...);
report_a.attach(report_b);
Later it's then possible to call report_a.request_ref()
or even for each frame in report_a.frames()
to call frame.request_ref()
(Note that request
ing currently requires a nightly compiler). I think this is almost the behavior you are looking for?
However, there is one issue: Report
has a generic for the current Context
, so you would need to specify which kind of Report
you want to get back.
Do you have a specific solution in mind? Maybe it makes sense to talk about a potential idea before opening a PR.
from hash.
My suggestion would be to have a new trait: ChangeContext
(or named differently), which is implemented for Report
and all tuple sizes, where each element must be a Report
, but their context doesn't need to be the same.
The thing that would need to be changed is that Frame
would have multiple sources.
Traversing the "graph" via .frames()
would be more challenging, and I don't have a good way of doing that just yet.
Displaying the error would also probably involve further indentation on a "cross-road," e.g., where two reports/frames are joined.
ChangeContext::change_context<T: Context>(self, context: T) -> Report<T>
if a: Report<C1>
, b: Report<C2>
, c: C3
then: (a, b).change_context(c) -> Report<C3>
from hash.
but to your earlier point, the provider API would kind of make sense, but I would need to know the context type in advance, then traverse through, which is doable, but a lot of pain
from hash.
I had a thought when traversing frames, we could, in theory, use BFS or DFS (or the topological sorting), but this would mean that we wouldn't be able to guarantee that every frame before a parent of the previous one.
from hash.
I thought about this for a long time and I think I came up with a possible solution.
First of all, the ReportImpl
abstraction should be removed, so Report
refers to Frame
directly. This can be done by not storing the backtrace/span trace on Report
but as an attachment, if they were captured. I think this moves both to a less "special" spot and make the behavior for the user more intuitive. I think this should be done regardless of related errors.
Now, a Report
is only a Frame
anymore. We now have two options (method naming TBD):
- Add a
Report::attach_report
method (which can be merged withattach
once specialization is a thing):
Stores theFrame
s of the attachedReport
inline ofself
- Add a
Report::combine
method:
Stores theFrame
s of the attachedReport
next to the current frame, e.g. by makingFrame::source
aVec<Frame>
I'd prefer the second option, especially as it's not special casing Report
when attaching but "simply" add a feature. For printing, I have a few thoughts. The structure is now a tree (but we keep pushing onto the root of it), Backtrace
and SpanTrace
as attachments instead could print the number of frames: Printing could happen like this:
Current context
| attachment
| attachment
|\
| Another context
| | attachment
| |
| Other context
| | attachment
| | backtrace with 15 frames
|
Other context
| attachment
| backtrace with 12 frames
| span trace with 3 frames
What do you think about that?
from hash.
Related Issues (20)
- GEN-68: `.into_report()` doesn't include error source chains HOT 8
- H-1: Support loading blocks in # Storybook
- [H-2] Make headings in hash.dev blog posts anchor-linkable HOT 1
- H-3: Add all HASH blocks to # Storybook
- [H-4] Add blurhash to hash.dev slide component HOT 1
- H-5: Automate publishing of new/updated HASH blocks to the block gallery & # Storybook
- H-7: Update hash.dev styles to match those in Figma HOT 2
- error[E0554]: `#![feature]` may not be used on the stable release channel HOT 10
- error[E0658]: use of unstable library feature 'lazy_cell' HOT 2
- [H-12] Change title of hash.dev/blog/[post] pages HOT 1
- [H-13] hash.dev: appropriately comma separate author names when articles have 3 or more HOT 1
- hCloud Error when running experiment for Python Model - Using Pandas library HOT 1
- `Report<E>` is not compatible with `std::error::Error` HOT 2
- Action Required: Fix Renovate Configuration HOT 2
- 🚀 Dependency Updates
- `IntoReport` is deprecated, but `ReportExt` that replaces it is not in `error-stack` HOT 2
- GEN-108(issue): Show some minimal but working example on the main documentation page HOT 7
- GEN-115: Way to disable error location and/or backtrace HOT 4
- Support generation of Context Implementation on a type with derive macro HOT 1
- GEN-132: Unclear initial examples in the docs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hash.