deno
deno copied to clipboard
Deno panicked formatting a HTML file
Version: Deno 2.0.2
I have the following file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Report</title>
<style>
body {
font-family: system-ui, sans-serif;
margin: 2em auto;
width: min(1200px, 90vw);
}
dl {
display: grid;
grid-template-columns: auto auto;
justify-content: start;
row-gap: 1em;
column-gap: 2em;
}
dt {
font-weight: 600;
}
dd {
margin: 0;
text-align: right;
}
</style>
</head>
<body>
<h1 id="title"></h1>
<div id="chart"></div>
<div id="details"></div>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script type="module">
const data = await (await fetch("./monthly-visits.json")).json();
const { title, labels, datasets } = data;
const fmt = new Intl.NumberFormat();
new frappe.Chart(
document.getElementById("chart"),
{
title,
type: "bar",
height: 300,
data: {
labels,
datasets: datasets.map(({ name, values }) => {
return { name, values, chartType: "bar" };
}),
},
},
);
document.title = title;
document.getElementById("title").innerText = title;
const details = document.getElementById("details");
details.innerHTML = `
${datasets.map(({ name, values }) => `
<h2>${name}</h2>
<dl>
${labels.map((label, index) => `
<dt>${label}</dt>
<dd>${fmt.format(values[index])}</dd>
`).join("")}
</dl>
`).join("")}
`;
</script>
</body>
</html>
Runing RUST_BACKTRACE=full deno fmt viewer.html I have this output:
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: macos x86_64
Version: 2.0.2
Args: ["deno", "fmt", "viewer.html"]
thread 'tokio-runtime-worker' panicked at cli/tools/fmt.rs:792:11:
Formatting not stable. Bailed after 5 tries. This indicates a bug in the formatter where it formats the file (/Users/oscarotero/www/toxo/viewer.html) differently each time. As a temporary workaround you can ignore this file.
stack backtrace:
0: 0x10c930673 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::haf41a54e7ed5fe07
1: 0x10b57061b - core::fmt::write::h526161fad96c5ad5
2: 0x10c8f65de - std::io::Write::write_fmt::h4de0398536c8b0e4
3: 0x10c9334aa - std::panicking::default_hook::{{closure}}::hffeef89117b5d267
4: 0x10c933017 - std::panicking::default_hook::h2f20b53f3264c5d5
5: 0x10b4117d8 - deno::setup_panic_hook::{{closure}}::h4647e1de7f306d01
6: 0x10c934542 - std::panicking::rust_panic_with_hook::h7919e8c602131afa
7: 0x10c933ed5 - std::panicking::begin_panic_handler::{{closure}}::h7bd628128f542977
8: 0x10c933e39 - std::sys::backtrace::__rust_end_short_backtrace::ha2fdb908654ed930
9: 0x10c933e2c - _rust_begin_unwind
10: 0x10e43345a - core::panicking::panic_fmt::h292eaa4d42e451fa
11: 0x10b05b5ac - tokio::runtime::task::raw::poll::h6bc75404ee29cf0f
12: 0x10ca77f3c - std::sys::backtrace::__rust_begin_short_backtrace::hc24085a67872c2b4
13: 0x10ca77c91 - core::ops::function::FnOnce::call_once{{vtable.shim}}::he256b09a4ff0d79e
14: 0x10c937adb - std::sys::pal::unix::thread::Thread::new::thread_start::hcd19cc58b6db093a
15: 0x7ff81f8c04e1 - __pthread_start
It looks like the cause is this piece of code inside the <script> tag:
details.innerHTML = `
${datasets.map(({ name, values }) => `
<h2>${name}</h2>
<dl>
${labels.map((label, index) => `
<dt>${label}</dt>
<dd>${fmt.format(values[index])}</dd>
`).join("")}
</dl>
`).join("")}
`;
If I remove this part, it works fine.