saxy icon indicating copy to clipboard operation
saxy copied to clipboard

Returning incorrect result in `handle_event` results in silent error

Open thbar opened this issue 1 year ago • 1 comments

Hi!

I discovered today something that caught me quite off-guard and which I find quite error-prone: if one returns, for instance, state, or "hello" instead of {:ok, state} in their implementation of handle_element, no error is raised.

I checked the documentation:

https://github.com/qcam/saxy/blob/dce77bfd4664f1ab90f76d3c847224dbbfabe820/lib/saxy/handler.ex#L15C1-L22C34

Returning {:ok, new_state} continues the parsing process with the new state.

Returning {:stop, anything} stops the prosing process immediately, and anything will be returned. This is usually handy when we want to get the desired return without parsing the whole file.

Returning {:halt, anything} stops the prosing process immediately, anything will be returned, together with the rest of buffer being parsed. This is usually handy when we want to get the desired return without parsing the whole file.

I have no idea at this point if this is easy to fix or not!

thbar avatar May 26 '24 14:05 thbar

Re-reading my issue, I realise this may be done on purpose, yet I'm concerned that just bogusly returning state instead of {:ok, state} could result into very incorrect programs, and would prefer an error here.

thbar avatar May 26 '24 14:05 thbar

I'll close for now!

thbar avatar Apr 06 '25 22:04 thbar