zed-industries/zed · error

drawing Canvas text

Error message

drawing Canvas text: {error:?}

What it means

Thrown in rasterize() when OffscreenCanvasRenderingContext2d::fill_text returns a rejected promise while drawing the glyph run onto the shared text canvas, after configure() and clear_rect succeeded. The browser refused to render the text — typically because the 2D context became invalid or a browser-internal draw failure occurred — so no pixel data exists yet and the rasterization of this text run fails for the caller.

Solutions

  1. Retry the rasterization once, optionally after recreating the OffscreenCanvas, since the failure is often a transient context error
  2. Fall back to an empty/blank raster for this glyph so rendering degrades instead of breaking the whole frame
  3. Log the JsValue via js_sys::Error::from to capture the browser-side reason before falling back
  4. Reuse the canvas-wide validation already in place (finite subpixel offsets, size/pixel caps) to rule out caller-side inputs before retrying
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at crates/gpui_web/src/canvas_text.rs:172 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@916fc2b8cb (2026-09-19). Data as JSON: /api/errors/0d2f437050c5e0da. Report an issue: GitHub.

Appendix: source

Thrown at crates/gpui_web/src/canvas_text.rs:172

        }
        if canvas.canvas.width() != width {
            canvas.canvas.set_width(width);
        }
        if canvas.canvas.height() != height {
            canvas.canvas.set_height(height);
        }
        canvas.configure(css_font)?;
        canvas
            .context
            .clear_rect(0.0, 0.0, f64::from(width), f64::from(height));
        canvas
            .context
            .fill_text(
                text,
                -f64::from(bounds.origin.x.0) + f64::from(subpixel_offset.0),
                -f64::from(bounds.origin.y.0) + f64::from(subpixel_offset.1),
            )
            .map_err(|error| anyhow!("drawing Canvas text: {error:?}"))?;
        let image = canvas
            .context
            .get_image_data(0.0, 0.0, f64::from(width), f64::from(height))
            .map_err(|error| anyhow!("reading Canvas text raster pixels: {error:?}"))?;
        let mut pixels = image.data().0;
        ensure!(
            pixels.len() == byte_count,
            "Canvas text raster returned {} bytes, expected {byte_count}",
            pixels.len()
        );
        if color {
            for pixel in pixels.chunks_exact_mut(4) {
                pixel.swap(0, 2);
            }
            Ok(pixels)
        } else {
            let mut alpha = Vec::new();
            alpha

View on GitHub (pinned to 916fc2b8cb)