Skip to content
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

Public Expression::evaluate() returns private Error #67

Closed
flying-sheep opened this issue Oct 30, 2015 · 4 comments · Fixed by #68
Closed

Public Expression::evaluate() returns private Error #67

flying-sheep opened this issue Oct 30, 2015 · 4 comments · Fixed by #68

Comments

@flying-sheep
Copy link
Contributor

the expression crate is private

pub trait Expression: Debug {
    fn evaluate<'a, 'd>(&self, context: &sxd_xpath::EvaluationContext<'a, 'd>)
        -> Result<sxd_xpath::Value<'d>, sxd_xpath::expression::Error>;
}

so if i’m not missing something, this crate is actually unusable for its main purpose: evaluating XPath expressions 😆

@shepmaster
Copy link
Owner

As I run off to work, I'll point to the integration test, which should exercise it as a user would. I'm sure I need to document something better; perhaps we can figure out what that something is.

@flying-sheep
Copy link
Contributor Author

surely ok()ping and unwrap()ing everything works for tests/quick&dirty, but in real code error inspection is of course useful.

xpath.evaluate(&context) here returns a Result<Value<'d>, expression::Error>. the expression::Error class is private, so anything except from Result (ok()) and Error trait methods (description()) is lost.

I need to document something better

anything would be a start 😉

but yeah, you can learn well from the integration tests if you find them (what i did)

@shepmaster
Copy link
Owner

You started by saying

unusable for its main purpose: evaluating XPath expressions

Which would imply that it is impossible to evaluate an expression. Is this true, or are you able to evaluate expressions, but the real problem is that the expression::Error type is private so any useful messages cannot be retrieved? Or are you hoping that the expression::Error type would have more information than the Error trait?

Perhaps I would understand better if you could include a small reproducible example of the code you've written and what you are trying to do.

@flying-sheep
Copy link
Contributor Author

oh, sorry, of course it’s not impossible to evaluate and stringify the error, just handling it like i do with every other error type:

use sxd_xpath::expression;

enum Error {
    XPath(expression::Error),
    Stuff(SomeOtherError),
}
impl From<expression::Error> for Error {...}
impl From<SomeOtherError> for Error {...}

...

let value = try!(xpath.evaluate(&context));

flying-sheep added a commit to flying-sheep/sxd-xpath that referenced this issue Dec 2, 2015
flying-sheep added a commit to flying-sheep/sxd-xpath that referenced this issue Dec 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants