<p dir="auto">The source code is contained within this repo:<br>
<a href="https://github.com/ChiKler/2D-container-of-2D-items-TS-JS/tree/36ef9c152bc3f27b0d2eef00ef599be696331fcf">https://github.com/ChiKler/2D-container-of-2D-items-TS-JS/tree/36ef9c152bc3f27b0d2eef00ef599be696331fcf</a></p>
<p dir="auto">Here's the sequence of commands you must execute in order to replicate this behaviour:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="git clone https://github.com/ChiKler/2D-container-of-2D-items-TS-JS.git
cd 2D-container-of-2D-items-TS-JS
git reset --hard 36ef9c152bc3f27b0d2eef00ef599be696331fcf
deno run --allow-net --allow-read --reload ./src/mod.test.ts
deno run --allow-net --allow-read ./src/mod.test.ts"><pre class="notranslate"><code class="notranslate">git clone https://github.com/ChiKler/2D-container-of-2D-items-TS-JS.git
cd 2D-container-of-2D-items-TS-JS
git reset --hard 36ef9c152bc3f27b0d2eef00ef599be696331fcf
deno run --allow-net --allow-read --reload ./src/mod.test.ts
deno run --allow-net --allow-read ./src/mod.test.ts
</code></pre></div>
<p dir="auto">As you can see, the first time you run the script, it throws some errors; the next time it doesn't.</p>
<p dir="auto">Edit: In order to fix this, I added some <code class="notranslate">// @ts-ignore</code> comments.<br>
Here's the commit that fixes it:<br>
<a href="https://github.com/ChiKler/2D-container-of-2D-items-TS-JS/commit/2adf4611d4f9b13ec4ec4d64524a66a491f7508d">https://github.com/ChiKler/2D-container-of-2D-items-TS-JS/commit/2adf4611d4f9b13ec4ec4d64524a66a491f7508d</a></p>
<p dir="auto">Because <code class="notranslate">std/http/server.ts</code> uses <code class="notranslate">MuxAsyncIterator</code> to serve up requests, any errors thrown there cannot be caught:</p>
<p dir="auto"></p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/denoland/deno/blob/e34a3b61f449cf6197b6d701770a85d9205c2a7b/std/http/server.ts#L235-L239">deno/std/http/server.ts</a>
    </p>
    <p class="mb-0 color-fg-muted">
        Lines 235 to 239
      in
      <a data-pjax="true" class="commit-tease-sha" href="/denoland/deno/commit/e34a3b61f449cf6197b6d701770a85d9205c2a7b">e34a3b6</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L235" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="235"></td>
          <td id="LC235" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-kos">[</span><span class="pl-smi">Symbol</span><span class="pl-kos">.</span><span class="pl-c1">asyncIterator</span><span class="pl-kos">]</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">AsyncIterableIterator</span><span class="pl-kos">&lt;</span><span class="pl-smi">ServerRequest</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L236" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="236"></td>
          <td id="LC236" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">const</span> <span class="pl-s1">mux</span>: <span class="pl-smi">MuxAsyncIterator</span><span class="pl-kos">&lt;</span><span class="pl-smi">ServerRequest</span><span class="pl-kos">&gt;</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">MuxAsyncIterator</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L237" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="237"></td>
          <td id="LC237" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-s1">mux</span><span class="pl-kos">.</span><span class="pl-en">add</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-en">acceptConnAndIterateHttpRequests</span><span class="pl-kos">(</span><span class="pl-s1">mux</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L238" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="238"></td>
          <td id="LC238" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">return</span> <span class="pl-s1">mux</span><span class="pl-kos">.</span><span class="pl-en">iterate</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L239" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="239"></td>
          <td id="LC239" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-kos">}</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto">The comments on <code class="notranslate">MuxAsyncIterator</code> make it clear that:</p>
<p dir="auto"></p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/denoland/deno/blob/e34a3b61f449cf6197b6d701770a85d9205c2a7b/std/async/mux_async_iterator.ts#L9-L14">deno/std/async/mux_async_iterator.ts</a>
    </p>
    <p class="mb-0 color-fg-muted">
        Lines 9 to 14
      in
      <a data-pjax="true" class="commit-tease-sha" href="/denoland/deno/commit/e34a3b61f449cf6197b6d701770a85d9205c2a7b">e34a3b6</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L9" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="9"></td>
          <td id="LC9" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-c">/** The MuxAsyncIterator class multiplexes multiple async iterators into a</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L10" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="10"></td>
          <td id="LC10" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-c"> * single stream. It currently makes a few assumptions:</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L11" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="11"></td>
          <td id="LC11" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-c"> * - The iterators do not throw.</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L12" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="12"></td>
          <td id="LC12" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-c"> * - The final result (the value returned and not yielded from the iterator)</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L13" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="13"></td>
          <td id="LC13" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-c"> *   does not matter; if there is any, it is discarded.</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L14" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="14"></td>
          <td id="LC14" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-c"> */</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto">And in situations where you have a TLS connection where the browser rejects the certificate, you end up with something like this with Deno dumping and no way to recover:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="error: Uncaught InvalidData: received corrupt message
    at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
    at Object.sendAsync ($deno$/ops/dispatch_json.ts:98:10)
    at async TLSListenerImpl.accept ($deno$/tls.ts:31:17)
    at async Server.acceptConnAndIterateHttpRequests (https://deno.land/std@0.50.0/http/server.ts:221:14)
    at async MuxAsyncIterator.callIteratorNext (https://deno.land/std@0.50.0/async/mux_async_iterator.ts:28:29)"><pre class="notranslate"><code class="notranslate">error: Uncaught InvalidData: received corrupt message
    at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
    at Object.sendAsync ($deno$/ops/dispatch_json.ts:98:10)
    at async TLSListenerImpl.accept ($deno$/tls.ts:31:17)
    at async Server.acceptConnAndIterateHttpRequests (https://deno.land/std@0.50.0/http/server.ts:221:14)
    at async MuxAsyncIterator.callIteratorNext (https://deno.land/std@0.50.0/async/mux_async_iterator.ts:28:29)
</code></pre></div>
<p dir="auto">We need a way to iterate that allows errors to be caught when iterating on HTTP server.</p>