-
Notifications
You must be signed in to change notification settings - Fork 39
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
Support :error tuples as a valid return value in event handlers #80
Comments
I think the idea behind the IMHO, Regarding adding P/S: I do have some small regrets, it would probably be more intuitive if the instructions were |
I would argue exactly the opposite: it would make handling of the error case simpler and more uniform. If a user doesn't care for the exact error type he can simply have one error clause. case Saxy.parse_string(...) do
{:ok, result} -> ...
{:error, error} -> raise error
end But if he likes to differentiate the error type he can still do it this way: case Saxy.parse_string(...) do
{:ok, result} -> ...
{:error, %Saxy.ParseError{} = e} -> ...
{:error, %RDF.XML.ParseError{} = e} -> ...
{:error, %Other.Error{} = e} -> ...
end |
Could I propose starting with |
Sure, no problem. I'm already working with the current approach. It was just a suggestion for improvement. But I actually went with with {:ok, result} <- Saxy.parse_string(...) do
# we're getting here with result being an error
end |
I want to leave +1 here to support this change. Found very confusing that Besides that, I think that since Saxy processing is an abstraction, the end-user shouldn't care whether the error has ocurred on the engine level, the handling level, or the XML level. I do think @marcelotto is right on this, the best way to encapsulate the possible error messages is to just return a plain |
Maybe I'm missing something, but is there a way to stop parsing with a
:error
tuple which is directly passed through as the overall result?I'm using Saxy for writing an RDF/XML parser which imposes some further restrictions on a valid document. So, I'd like to return a
:error
tuple in the event handlers when encountering an error, which I'd expect to be passed through directly as the result ofSaxy.parse_string/3
, but currently this results in this:I'm aware of the
:halt
and:stop
return patterns, which could be used for this scenario of course, but neither of them feels quite right::stop
the:error
tuple is wrapped in a:ok
tuple:halt
the:error
tuple is wrapped in a three element:halt
tupleWhat do you think of supporting
:error
tuples as an additional return pattern in the handlers, which will become the result ofSaxy.parse_string/3
directly?The text was updated successfully, but these errors were encountered: