[whatwg/encoding] Reset TextDecoder when decode() throws (PR #369)

When decode() threw while streaming, the next invocation continued with the decoder, I/O queue, and BOM seen as they were when the error occurred. As the output up to the error is not returned, continuing from there is not useful, and implementations disagreed on what remained. Instead the next invocation now starts anew.

TextDecoderStream is unaffected, as an error there errors the stream.

Also remove the "Otherwise" steps that follow early returns in decode(), which removes a level of nesting.

Fixes #358 and fixes #359.

<!--
Thank you for contributing to the Encoding Standard! Please describe the change you are making and complete the checklist below if your change is not editorial.

When you submit this PR, and each time you edit this comment (including checking a checkbox through the UI!), PR Preview will run and update it. As such make any edits in one go and only after PR Preview has run.

If you think your PR is ready to land, please double-check that the build is passing and the checklist is complete before pinging.
-->

- [ ] At least two implementers are interested (and none opposed):
   * WebKit
   * Gecko: https://github.com/whatwg/encoding/issues/359#issuecomment-6980176216
- [ ] [Tests](https://github.com/web-platform-tests/wpt) are written and can be reviewed and commented upon at:
   * WebKit PR, to be exported (link to follow)
- [ ] [Implementation bugs](https://github.com/whatwg/meta/blob/main/MAINTAINERS.md#handling-pull-requests) are filed:
   * Chromium: …
   * Gecko: …
   * WebKit: https://bugs.webkit.org/show_bug.cgi?id=332174
   * Deno: …
   * Node.js: …
- [ ] [MDN issue](https://github.com/whatwg/meta/blob/main/MAINTAINERS.md#handling-pull-requests) is filed: …
- [x] The top of this comment includes a [clear commit message](https://github.com/whatwg/meta/blob/main/COMMITTING.md) to use. <!-- If you created this PR from a single commit, Github copied its message. Otherwise, you need to add a commit message yourself. -->

(See [WHATWG Working Mode: Changes](https://whatwg.org/working-mode#changes) for more details.)


<!--
    This comment and the below content is programmatically generated.
    You may add a comma-separated list of anchors you'd like a
    direct link to below (e.g. #idl-serializers, #idl-sequence):

    Don't remove this comment or modify anything below this line.
    If you don't want a preview generated for this pull request,
    just replace the whole of this comment's content by "no preview"
    and remove what's below.
-->
***

### :boom: Error: 422 Unprocessable Entity :boom: ###

[PR Preview](https://github.com/specinfra/pr-preview#pr-preview) failed to build. _(Last tried on Nov 18, 2026, 3:48 PM UTC)_.

<details>
<summary>More</summary>


PR Preview relies on a number of web services to run. There seems to be an issue with the following one:

:rotating_light: [Spec Generator](https://www.w3.org/publications/spec-generator/) - Spec Generator is the web service used to build bikeshed/ReSpec specs

:link: [Related URL](https://www.w3.org/publications/spec-generator/?type=bikeshed-spec&output=html&url=https%3A%2F%2Fraw.githubusercontent.com%2Fwhatwg%2Fencoding%2Fc8495080af8c41cdbd0b068092203e873bc23076%2Fencoding.bs&force=1&md-status=LS-PR&md-Text-Macro=PR-NUMBER%20369)

**Error output:**

```json
[
    {
        "lineNum": "1297:7",
        "messageType": "warning",
        "text": "Highlighting 'javascript' uses the legacy slow highlighter. Recommend finding a TextMate grammar and using it with 'Highlight Grammar', or filing an issue on Bikeshed; see https://speced.github.io/bikeshed/#missing-languages."
    },
    {
        "lineNum": null,
        "messageType": "failure",
        "text": "Did not generate, due to errors exceeding the allowed error level."
    }
]
```

_This seems to be an issue with the [Spec Generator](https://www.w3.org/publications/spec-generator/) service. PR Preview doesn't manage this service and so has no control over it. If you've identified an issue with it, you can [report the issue to the maintainers of Spec Generator](https://github.com/w3c/spec-generator/issues/new) directly. Please be courteous. Thank you!_

_If you don't have enough information above to solve the error by yourself or if the issue doesn't seem related to Spec Generator, you can [file an issue with PR Preview](https://github.com/specinfra/pr-preview/issues/new?title=Unidentified%20Error&body=See%20whatwg/encoding%23369.)._

</details>

You can view, comment on, or merge this pull request online at:

  https://github.com/whatwg/encoding/pull/369

-- Commit Summary --

  * Reset TextDecoder when decode() throws

-- File Changes --

    M encoding.bs (23)

-- Patch Links --

https://github.com/whatwg/encoding/pull/369.patch
https://github.com/whatwg/encoding/pull/369.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/encoding/pull/369
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/encoding/pull/369@github.com>

Received on Wednesday, 18 November 2026 15:48:41 UTC