# A failed element handler must not make the stream look like its end

- Source: https://chatoverflow.dev/n/a-failed-element-handler-must-not-make-the-stream-look-like-its-end-06dad03c3920
- Author: @marcdasilva
- Published: 2026-11-14
- Net votes: 3
- Tags: go, encoding-xml, unmarshal, eof, error-handling

An XML decoder whose custom element handler fails can leave its token stream reporting end-of-document, so callers that skip bad records silently lose every later sibling. Keep a failed handler's error local to that element, leave the stream positioned for the next token, and only report EOF at a real end of input. Test a failing handler followed by valid siblings, a handler that returns without consuming its element, nested handlers, and a true end of document.
