-
Notifications
You must be signed in to change notification settings - Fork 1
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
error handling #1
Comments
Reopening (see #12 (comment) + following 2 comments). Look at alternatives to provide
/// Runtime error with stack trace.
#[derive(Clone, Debug)]
pub struct Traced<T: Clone, Debug> {
pub error: T,
/// Trace entries which may have location and/or another error. Maybe another struct.
pub trace: Vec<(Location, Option<T>)>,
} |
I did it quite similar to your suggestion - but instead of We can use the inner error for rust-style error-composition What do you think? |
I am willing to try it :) |
Ok. :-) Btw: I was not sure about one detail - should I think Deref is usually reserved for smart pointers and Newtype-Tuple-Structs like |
I would do no magic until really needed. So I think (c) until proven otherwise :) |
Ok, I will remove (a). I had another thought about it. I think what we want is composable errors and giving the caller the flexibility to convert our traced errors into opaque trait objects. If a consumer of Twig wants to convert our
The try macro will try to call
So actually I think we should do (b). |
Ok. |
It would be great, if we find a common way here. That will make everything else a lot easier!
Ok, here is our starting point :-)
twig-rust
return err!(ParserErrorCode::Logic, "Unexpected end of token stream")
, where filename:line:column and module-path is collected by the err!-macro automatically. It also supports formattingerr!(..., "Hello {name}", name = "world")
. This is something I find quite useful.try!( .... )
a lot, where try! will convert different error-types for me, because my error-types implement a couple of Into-traits, e.g. a SyntaxError implements Into, via this macro:impl_convert_exception!(SyntaxErrorCode, LexerErrorCode, LexerErrorCode::SyntaxError);
Definitions are in: src/error/* - but I am sure, it has room for improvement. It definitely needs some cleanup, due to boiler-plate when defining new error definitions.
twig-rs
I am keeping all errors in enums/structs and then converting them to string on actual display. There are 3 groups:
template
for lexer and parser errors,engine
for loading/caching, andruntime
which is a bit in flux. On top of that, there is master twigError
which can contain any of these children, and in case of engine/runtime, the chain of error causes. Of course, all chilren are implementing Into trait to be converted to "master" error.I have found one idea useful: separating location from actual error. There is this At struct which wraps actual error inside. To convert to it, there is method on error named
at
, which requires location in file. So I do this:Note that I only have line numbers, but I was planning to expand this to line/col later.
The text was updated successfully, but these errors were encountered: