You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my use case I'm providing a library that helps with parsing a specific kind of token stream syntax, namely something HTML/JSX-ish: syn-rsx. I'd like consumers of the library to customize their error behavior depending on what goes wrong while parsing the provided tokens. E.g. if a closing HTML tag is missing there's currently a hard-coded string provided to input.error. Instead I'd like to return an error enum variant such as syn_rsx::Error::MissingClosingTag, ideally with additional context information attached.
AFAIK this currently isn't possible since Parser always expects a syn::Error to be returned, which does not allow to attach custom context information, but maybe I'm missing something?
Possible solutions
Maybe Parser could allow to return everything that implements std::error::Error as an error?
Alternatively syn::Error could allow attaching arbitrary context information? E.g. via adding
syn::Error::set_context(context: T)
syn::Error::get_context() -> T
methods?
Possible workaround
Allow consumers of syn_rsx to customize just the error strings that are passed to input.error via some sort of configuration.
I would prefer not to build anything for this into this library. But there is room in the ecosystem for a different library to implement something for this use case.
In my use case I'm providing a library that helps with parsing a specific kind of token stream syntax, namely something HTML/JSX-ish:
syn-rsx
. I'd like consumers of the library to customize their error behavior depending on what goes wrong while parsing the provided tokens. E.g. if a closing HTML tag is missing there's currently a hard-coded string provided toinput.error
. Instead I'd like to return an error enum variant such assyn_rsx::Error::MissingClosingTag
, ideally with additional context information attached.AFAIK this currently isn't possible since
Parser
always expects asyn::Error
to be returned, which does not allow to attach custom context information, but maybe I'm missing something?Possible solutions
Maybe
Parser
could allow to return everything that implementsstd::error::Error
as an error?Alternatively
syn::Error
could allow attaching arbitrary context information? E.g. via addingsyn::Error::set_context(context: T)
syn::Error::get_context() -> T
methods?
Possible workaround
Allow consumers of
syn_rsx
to customize just the error strings that are passed toinput.error
via some sort of configuration.Downstream issue: stoically/syn-rsx#12
The text was updated successfully, but these errors were encountered: