I'm pretty new to Swift, so it's possible I'm missing something, but from what I've found searching this forum and other places, it seems like the inability to make iterators throw is a known issue. It looks like it's been solved for async iterators, but sync ones are still affected for backwards-compatibility reasons. But most of the posts I find are a few years old and so might be out of date.
Assuming there's no one-size-fits-all solution that I just haven't found yet, what options are there? The only thing I can think of is to convert it to an async iterator, but given that I don't actually need asynchronicity, that seems suboptimal.
That doesn't compose very well, but it's generally been sufficient for the things I've needed. If you wanted to do something better, you could have the decoder invoke a callback closure and capture the flag in to some external state.
None of these options are really great though, I'm afraid. My hopes are all on the collection redesign @lorentey is cooking up having support for throwing sequences.