cloudflare/quiche · error

cannot find canvas

Error message

cannot find canvas {}

What it means

In qlog-dancer's wasm (browser) build, make_chart_canvas_area panics when plotters' CanvasBackend cannot find an HTML <canvas> element with the requested id. The chart drawing area is created from a DOM canvas; a missing or mistyped id means plotting cannot proceed. Note CanvasBackend::new returns Option in this setup, hence the unwrap_or_else panic.

Solutions

  1. Ensure the HTML contains <canvas id="<canvas_id>"> exactly matching the id used in the plot call.
  2. Run the plot code after DOMContentLoaded/onload, not before the canvas exists.
  3. If you renamed a canvas in the HTML, update the corresponding id in the Rust plotting code (or vice versa).

Example fix

// before (html)
<canvas id="main-chart-old"></canvas>
// after
<canvas id="main-chart"></canvas> // matches make_chart_canvas_area("main-chart", ...)
Defensive patterns

Strategy: validation

Validate before calling

// before calling the plot function
let el = web_sys::window().unwrap().document().unwrap().get_element_by_id(canvas_id);
assert!(el.is_some(), "canvas {} missing from DOM", canvas_id);

Prevention

When it happens

Trigger: Calling any plot function (plot_main_plot, plot_packet_received, plot_cc_plot, etc.) in the wasm app when the DOM has no <canvas id="..."> matching the canvas_id passed to make_chart_canvas_area.

Common situations: HTML template and Rust plot code out of sync (renamed canvas id); plot invoked before the DOM finished loading; JS interop passing a wrong id; running the wasm app with an outdated index.html.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of cloudflare/quiche@9f96daa2c2 (2026-09-08). Data as JSON: /api/errors/86a0e9ed2e21e842. Report an issue: GitHub.

Appendix: source

Thrown at qlog-dancer/src/plots/mod.rs:186

    }
}

#[cfg(not(target_arch = "wasm32"))]
pub fn make_chart_bitmap_area(
    path: &str, size: ChartSize, colors: PlotColors, margin: ChartMargin,
) -> DrawingArea<plotters::prelude::BitMapBackend<'_>, plotters::coord::Shift> {
    let backend = BitMapBackend::new(path, (size.width, size.height));
    let area = backend.into_drawing_area();
    area.fill(&colors.fill).unwrap();
    area.margin(margin.top, margin.bottom, margin.left, margin.right)
}

#[cfg(target_arch = "wasm32")]
pub fn make_chart_canvas_area(
    canvas_id: &str, colors: PlotColors, margin: ChartMargin,
) -> plotters::drawing::DrawingArea<CanvasBackend, plotters::coord::Shift> {
    let backend = CanvasBackend::new(canvas_id)
        .unwrap_or_else(|| panic!("cannot find canvas {}", canvas_id));
    let area = backend.into_drawing_area();
    area.fill(&colors.fill).unwrap();
    area.margin(margin.top, margin.bottom, margin.left, margin.right)
}

fn make_chart_config(
    title: &str, params: &PlotParameters, filename: &str, ds: &Datastore,
    ty: &ChartOutputType,
) -> ChartConfig {
    let chart_config = ChartConfig {
        title: title.into(),
        input_filename: filename.into(),
        clamp: params.clamp.clone(),
        app_proto: ds.application_proto,
        host: ds.host.clone(),
        session_id: ds.session_id,
        ty: ty.clone(),
    };

View on GitHub (pinned to 9f96daa2c2)