<h1 dir="auto">Problem description</h1>
<p dir="auto">Running the deno coverage command against the coverage report of code that printed any unicode character will lead to a panic.</p>
<h1 dir="auto">Steps to reproduce</h1>
<p dir="auto">Create a sample file that prints any unicode character, e.g. <code class="notranslate">app.ts</code>:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="export function cheers() {
  console.log('🍻');
}

cheers();"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-k">function</span> <span class="pl-en">cheers</span><span class="pl-kos">(</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">log</span><span class="pl-kos">(</span><span class="pl-s">'🍻'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-en">cheers</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Create a simple test that calls the given function, e.g. <code class="notranslate">app.test.ts</code>:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import { cheers } from './app.ts'

Deno.test(&quot;It should print an emoji&quot;, () =&gt; {
    cheers();
})"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-s1">cheers</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'./app.ts'</span>

<span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-s">"It should print an emoji"</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-en">cheers</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<p dir="auto">Now try to create a coverage report and watch Deno panic.</p>
<h1 dir="auto">Output without backtrace</h1>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[tmp]➡ deno run app.ts
🍻
[tmp]➡ deno test app.test.ts --coverage=cov
🍻
running 1 test from file:///tmp/app.test.ts
test It should print an emoji ...🍻

 ok (6ms)

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (64ms)

[tmp]➡ deno coverage cov

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: linux x86_64
Version: 1.19.3
Args: [&quot;deno&quot;, &quot;coverage&quot;, &quot;cov&quot;]

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BadJson(Error(&quot;invalid unicode code point&quot;, line: 1, column: 280))', cli/tools/coverage/mod.rs:173:57
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[tmp]➡ "><pre lang="log" class="notranslate"><code class="notranslate">[tmp]➡ deno run app.ts
🍻
[tmp]➡ deno test app.test.ts --coverage=cov
🍻
running 1 test from file:///tmp/app.test.ts
test It should print an emoji ...🍻

 ok (6ms)

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (64ms)

[tmp]➡ deno coverage cov

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: linux x86_64
Version: 1.19.3
Args: ["deno", "coverage", "cov"]

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BadJson(Error("invalid unicode code point", line: 1, column: 280))', cli/tools/coverage/mod.rs:173:57
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[tmp]➡ 
</code></pre></div>
<h1 dir="auto">Output with backtrace</h1>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[tmp]➡ RUST_BACKTRACE=1 deno coverage cov

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: linux x86_64
Version: 1.19.3
Args: [&quot;deno&quot;, &quot;coverage&quot;, &quot;cov&quot;]

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BadJson(Error(&quot;invalid unicode code point&quot;, line: 1, column: 280))', cli/tools/coverage/mod.rs:173:57
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: core::result::unwrap_failed
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/result.rs:1690:5
   3: deno::tools::coverage::cover_files::{{closure}}
   4: &lt;core::future::from_generator::GenFuture&lt;T&gt; as core::future::future::Future&gt;::poll
   5: deno::main::{{closure}}
   6: &lt;core::future::from_generator::GenFuture&lt;T&gt; as core::future::future::Future&gt;::poll
   7: deno_runtime::tokio_util::run_basic
   8: deno::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace."><pre lang="log" class="notranslate"><code class="notranslate">[tmp]➡ RUST_BACKTRACE=1 deno coverage cov

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: linux x86_64
Version: 1.19.3
Args: ["deno", "coverage", "cov"]

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BadJson(Error("invalid unicode code point", line: 1, column: 280))', cli/tools/coverage/mod.rs:173:57
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: core::result::unwrap_failed
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/result.rs:1690:5
   3: deno::tools::coverage::cover_files::{{closure}}
   4: &lt;core::future::from_generator::GenFuture&lt;T&gt; as core::future::future::Future&gt;::poll
   5: deno::main::{{closure}}
   6: &lt;core::future::from_generator::GenFuture&lt;T&gt; as core::future::future::Future&gt;::poll
   7: deno_runtime::tokio_util::run_basic
   8: deno::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
</code></pre></div>
<p dir="auto">Hi, I am having an issue where the output of <code class="notranslate">deno coverage</code> appears inaccurate. I was able to narrow it down to a minimal example; instructions below. I hope it is reproducible. The problem goes away if the emojis or the unused function <code class="notranslate">h</code> are removed. Removing a single emoji removes line 2 from the coverage report, but still inaccurately keeps line 3. I have not tested it with other emojis <g-emoji class="g-emoji" alias="relaxed" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/263a.png">☺️</g-emoji></p>
<p dir="auto">This is the <code class="notranslate">mod.ts</code> file:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="export default function () {
  return &quot;📣❓&quot;;
}

function h() {}"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-k">default</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">return</span> <span class="pl-s">"📣❓"</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">function</span> <span class="pl-en">h</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span><span class="pl-kos">}</span></pre></div>
<p dir="auto">This is the <code class="notranslate">mod_test.ts</code> file:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import f from &quot;./mod.ts&quot;;

Deno.test(&quot;test&quot;, () =&gt; {
  f()
});"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">f</span> <span class="pl-k">from</span> <span class="pl-s">"./mod.ts"</span><span class="pl-kos">;</span>

<span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-s">"test"</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-en">f</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">These are the shell commands:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="deno test --coverage=.cov
deno coverage .cov
rm -rf .cov"><pre class="notranslate">deno <span class="pl-c1">test</span> --coverage=.cov
deno coverage .cov
rm -rf .cov</pre></div>
<p dir="auto">This is the output of <code class="notranslate">deno coverage</code>. As far as I understand it, line 2 and 3 should be covered:</p>
<div class="highlight highlight-text-adblock notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content=" cover file:///home/mod.ts ... 25.000% (1/4)
   2 |   return &quot;📣❓&quot;;
   3 | }
-----|-----
   5 | function h() {}"><pre class="notranslate"> cover file:///home/mod.ts ... 25.000% (1/4)
   2 |   return "📣❓";
   3 | }
-----|-----
   5 | function h() {}</pre></div>
<p dir="auto">This is the output of <code class="notranslate">deno --version</code>:</p>
<div class="highlight highlight-text-adblock notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="deno 1.11.0 (release, x86_64-unknown-linux-gnu)
v8 9.1.269.35
typescript 4.3.2"><pre class="notranslate">deno 1.11.0 (release, x86_64-unknown-linux-gnu)
v8 9.1.269.35
typescript 4.3.2</pre></div>