<p dir="auto">Panic on format:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', cli\fmt_errors.rs:211:45"><pre class="notranslate"><code class="notranslate">thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', cli\fmt_errors.rs:211:45
</code></pre></div>
<p dir="auto">It only panic's specifically on this specific line:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="if (name === this.#DB[i].name) throw new Error(name);"><pre class="notranslate"><span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">name</span> <span class="pl-c1">===</span> <span class="pl-smi">this</span><span class="pl-kos">.</span>#DB<span class="pl-kos">[</span><span class="pl-s1">i</span><span class="pl-kos">]</span><span class="pl-kos">.</span><span class="pl-c1">name</span><span class="pl-kos">)</span> <span class="pl-k">throw</span> <span class="pl-k">new</span> <span class="pl-smi">Error</span><span class="pl-kos">(</span><span class="pl-s1">name</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">I wanted to provide a log but idk how to run with <code class="notranslate">RUST_BACKTRACE=1</code></p>
<p dir="auto">deno info:</p>
<p dir="auto">deno 1.7.1 (release, x86_64-pc-windows-msvc)<br>
v8 8.9.255.3<br>
typescript 4.1.3</p>
<p dir="auto">I'm experiencing a strange bug with <code class="notranslate">Deno</code>.</p>
<p dir="auto">When a exception is thrown the main process panics. This is the trace:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', cli\fmt_errors.rs:86:8
stack backtrace:
   0:     0x7ff7af88a45b - &lt;unknown&gt;
   1:     0x7ff7af53cecc - &lt;unknown&gt;
   2:     0x7ff7af889483 - &lt;unknown&gt;
   3:     0x7ff7af888bb8 - &lt;unknown&gt;
   4:     0x7ff7af887d2e - &lt;unknown&gt;
   5:     0x7ff7af88efe5 - &lt;unknown&gt;
   6:     0x7ff7af53a4b0 - &lt;unknown&gt;
   7:     0x7ff7af53a2cc - &lt;unknown&gt;
   8:     0x7ff7af36cbf2 - &lt;unknown&gt;
   9:     0x7ff7af48ada8 - &lt;unknown&gt;
  10:     0x7ff7af48b345 - &lt;unknown&gt;
  11:     0x7ff7af53cecc - &lt;unknown&gt;
  12:     0x7ff7af751885 - &lt;unknown&gt;
  13:     0x7ff7af349c1d - &lt;unknown&gt;
  14:     0x7ff7af4daf6f - &lt;unknown&gt;
  15:     0x7ff7af8aa3f6 - &lt;unknown&gt;
  16:     0x7ff7af4ea67e - &lt;unknown&gt;
  17:     0x7ff7b048bf10 - CrashForExceptionInNonABICompliantCodeRange
  18:     0x7ff8e9777bd4 - BaseThreadInitThunk
  19:     0x7ff8ea16ce51 - RtlUserThreadStart"><pre class="notranslate"><code class="notranslate">thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', cli\fmt_errors.rs:86:8
stack backtrace:
   0:     0x7ff7af88a45b - &lt;unknown&gt;
   1:     0x7ff7af53cecc - &lt;unknown&gt;
   2:     0x7ff7af889483 - &lt;unknown&gt;
   3:     0x7ff7af888bb8 - &lt;unknown&gt;
   4:     0x7ff7af887d2e - &lt;unknown&gt;
   5:     0x7ff7af88efe5 - &lt;unknown&gt;
   6:     0x7ff7af53a4b0 - &lt;unknown&gt;
   7:     0x7ff7af53a2cc - &lt;unknown&gt;
   8:     0x7ff7af36cbf2 - &lt;unknown&gt;
   9:     0x7ff7af48ada8 - &lt;unknown&gt;
  10:     0x7ff7af48b345 - &lt;unknown&gt;
  11:     0x7ff7af53cecc - &lt;unknown&gt;
  12:     0x7ff7af751885 - &lt;unknown&gt;
  13:     0x7ff7af349c1d - &lt;unknown&gt;
  14:     0x7ff7af4daf6f - &lt;unknown&gt;
  15:     0x7ff7af8aa3f6 - &lt;unknown&gt;
  16:     0x7ff7af4ea67e - &lt;unknown&gt;
  17:     0x7ff7b048bf10 - CrashForExceptionInNonABICompliantCodeRange
  18:     0x7ff8e9777bd4 - BaseThreadInitThunk
  19:     0x7ff8ea16ce51 - RtlUserThreadStart
</code></pre></div>
<p dir="auto">I don't know how to reproduce the bug but it happened in my project so I tried to isolate it in a separated branch:<br>
<a href="https://github.com/AndreJesusBrito/WebAssembly-Language-Compiler/tree/rust-exception-bug-isolation">https://github.com/AndreJesusBrito/WebAssembly-Language-Compiler/tree/rust-exception-bug-isolation</a></p>
<p dir="auto">The bug happens in file <code class="notranslate">src/SyntaxAnalysis/SyntaxRule.ts</code> at line 25 when I throw an exception.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="...
public getDerivation(terminal: string): RuleDerivation {
  const derivation = this.derivations.get(terminal);
  if (derivation) {
    return {
      derivationSymbols: [...derivation.derivationSymbols].reverse(),
      actions: derivation.actions,
    };
  } else {
    throw SyntaxError(&quot;Unexpected token '&quot; + terminal + &quot;' at rule &quot; + this._name);            // THIS IS LINE 25
  }
}

public setDerivation(rule: SyntaxSymbol[], actions: ActionObj[], ...terminals: string[]): void {
  for (const terminal of terminals) {
    if (this.derivations.get(terminal) instanceof Array) {
      console.warn(&quot;'&quot; + terminal + &quot;' repeated terminal for rule &quot; + this._name);
..."><pre class="notranslate">...
<span class="pl-k">public</span> <span class="pl-en">getDerivation</span><span class="pl-kos">(</span><span class="pl-s1">terminal</span>: string<span class="pl-kos">)</span>: <span class="pl-smi">RuleDerivation</span> <span class="pl-kos">{</span>
  <span class="pl-k">const</span> <span class="pl-s1">derivation</span> <span class="pl-c1">=</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">derivations</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s1">terminal</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">derivation</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">return</span> <span class="pl-kos">{</span>
      <span class="pl-c1">derivationSymbols</span>: <span class="pl-kos">[</span>...<span class="pl-s1">derivation</span><span class="pl-kos">.</span><span class="pl-c1">derivationSymbols</span><span class="pl-kos">]</span><span class="pl-kos">.</span><span class="pl-en">reverse</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
      <span class="pl-c1">actions</span>: <span class="pl-s1">derivation</span><span class="pl-kos">.</span><span class="pl-c1">actions</span><span class="pl-kos">,</span>
    <span class="pl-kos">}</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span> <span class="pl-k">else</span> <span class="pl-kos">{</span>
    <span class="pl-k">throw</span> <span class="pl-smi">SyntaxError</span><span class="pl-kos">(</span><span class="pl-s">"Unexpected token '"</span> <span class="pl-c1">+</span> <span class="pl-s1">terminal</span> <span class="pl-c1">+</span> <span class="pl-s">"' at rule "</span> <span class="pl-c1">+</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">_name</span><span class="pl-kos">)</span><span class="pl-kos">;</span>            <span class="pl-c">// THIS IS LINE 25</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-s1">public</span><span class="pl-kos"></span> <span class="pl-en">setDerivation</span><span class="pl-kos">(</span><span class="pl-s1">rule</span>: <span class="pl-smi">SyntaxSymbol</span><span class="pl-kos">[</span><span class="pl-s1"></span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-s1">actions</span>: <span class="pl-smi">ActionObj</span><span class="pl-kos">[</span><span class="pl-s1"></span><span class="pl-kos">]</span><span class="pl-kos">,</span> ...<span class="pl-s1">terminals</span>: string<span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">)</span>: <span class="pl-k">void</span> <span class="pl-kos">{</span>
  <span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-k">const</span> <span class="pl-s1">terminal</span> <span class="pl-k">of</span> <span class="pl-s1">terminals</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">derivations</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s1">terminal</span><span class="pl-kos">)</span> <span class="pl-k">instanceof</span> <span class="pl-smi">Array</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">warn</span><span class="pl-kos">(</span><span class="pl-s">"'"</span> <span class="pl-c1">+</span> <span class="pl-s1">terminal</span> <span class="pl-c1">+</span> <span class="pl-s">"' repeated terminal for rule "</span> <span class="pl-c1">+</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">_name</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
...</pre></div>
<p dir="auto">Even though I'm using a SyntaxError (that is not a very good idea and will change later) it seems to happen for any error including the base Error class.</p>
<p dir="auto">The most strange thing to me is that by changing the white space on this file it can work correctly.<br>
For example, when I remove line 28 it works fine:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="error: Uncaught SyntaxError: Unexpected token '' at rule none
  public setDerivation(rule: SyntaxSymbol[], actions: ActionObj[], ...terminals: string[]): void {
            ^
    at SyntaxRule.getDerivation (file:///C:/Users/Andr%C3%A9%20Brito/Documents/GitHub/WebAssembly-Language-Compiler/src/SyntaxAnalysis/SyntaxRule.ts:28:13)
    at file:///C:/Users/Andr%C3%A9%20Brito/Documents/GitHub/WebAssembly-Language-Compiler/src/main.ts:4:1"><pre class="notranslate"><code class="notranslate">error: Uncaught SyntaxError: Unexpected token '' at rule none
  public setDerivation(rule: SyntaxSymbol[], actions: ActionObj[], ...terminals: string[]): void {
            ^
    at SyntaxRule.getDerivation (file:///C:/Users/Andr%C3%A9%20Brito/Documents/GitHub/WebAssembly-Language-Compiler/src/SyntaxAnalysis/SyntaxRule.ts:28:13)
    at file:///C:/Users/Andr%C3%A9%20Brito/Documents/GitHub/WebAssembly-Language-Compiler/src/main.ts:4:1
</code></pre></div>
<p dir="auto">I'm running using the command:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="deno run src\main.ts"><pre class="notranslate"><code class="notranslate">deno run src\main.ts
</code></pre></div>
<p dir="auto">and my specs are:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="deno 1.2.2
v8 8.5.216
typescript 3.9.2
OS: Windows_NT x64 10.0.18362"><pre class="notranslate"><code class="notranslate">deno 1.2.2
v8 8.5.216
typescript 3.9.2
OS: Windows_NT x64 10.0.18362
</code></pre></div>
<p dir="auto">Hope this helps! :)</p>