Skip to content

Best practice of error handling? #716

Answered by udoprog
Reverier-Xu asked this question in Q&A
Discussion options

You must be logged in to vote

You have two options on the edge, either everything needs to be a Result so you can convert it into a std::result::Result<T, E>, or you'll have to typecheck by comparing the value of Value::type_hash with the corresponding type hash and only perform the conversion if they match.

The former is what's encouraged. Try to keep your types coherent, at least at the edge of your function. In your case that would mean returning Ok(sth) instead of just sth.

The latter is possible, but won't really be easy to work with since calculating a type hash is a bit tricky right now. In git we actually have a macro that can do it which will be in the next release.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Reverier-Xu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants