d2lang/d2 · error

failed to fully compile (partial render written) %s: %w

Error message

failed to fully compile (partial render written) %s: %w

What it means

Run wraps errors from compile() with 'failed to fully compile (partial render written)' when compile reported that an output file was already (partially) written before the failure. The %w-wrapped inner error carries the root cause.

Source

Thrown at d2cli/main.go:418

		if err != nil {
			return xmain.UsageErrorf("invalid target: %s", *targetFlag)
		}
		boardPath = key.StringIDA()
	}

	ctx, cancel := timelib.WithTimeout(ctx, time.Minute*2)
	defer cancel()

	animateInterval := *animateIntervalFlag
	if outputFormat == GIF && animateInterval == 0 {
		animateInterval = 1000
		ms.Log.Debug.Printf("GIF export: animate-interval not specified, defaulting to 1000ms")
	}

	_, written, err := compile(ctx, ms, plugins, nil, layoutFlag, renderOpts, fontFamily, monoFontFamily, animateInterval, inputPath, outputPath, boardPath, noChildren, *bundleFlag, *forceAppendixFlag, pw.Browser, outputFormat, *asciiModeFlag)
	if err != nil {
		if written {
			return fmt.Errorf("failed to fully compile (partial render written) %s: %w", ms.HumanPath(inputPath), err)
		}
		return fmt.Errorf("failed to compile %s: %w", ms.HumanPath(inputPath), err)
	}
	return nil
}

func LayoutResolver(ctx context.Context, ms *xmain.State, plugins []d2plugin.Plugin) func(engine string) (d2graph.LayoutGraph, error) {
	cached := make(map[string]d2graph.LayoutGraph)
	return func(engine string) (d2graph.LayoutGraph, error) {
		if c, ok := cached[engine]; ok {
			return c, nil
		}

		plugin, err := d2plugin.FindPlugin(ctx, plugins, engine)
		if err != nil {
			if errors.Is(err, exec.ErrNotFound) {
				return nil, layoutNotFound(ctx, plugins, engine)
			}

View on GitHub (pinned to 0d69dca6f5)

Solutions

  1. Read the wrapped inner error (%w chain) for the actual root cause and fix that
  2. Delete the partially written output directory/file before re-running
  3. Re-run with debug logging to locate the stage that failed after writing

Example fix

// before
// err: failed to fully compile (partial render written) out/index.svg: ...plugin error...
// after: inspect inner cause, e.g. fix layout engine name in the .d2 file, then
d2 input.d2 out.svg
Defensive patterns

Strategy: try-catch

Try / catch

if err := d2cli.Run(...); err != nil {
    var inner error
    if errors.Unwrap(err) != nil { inner = errors.Unwrap(err) }
    log.Printf("compile failed (partial output may exist): %v; cause: %v", err, inner)
    os.RemoveAll(partialOutDir) // clean partial render
}

Prevention

When it happens

Trigger: Any compile-time failure (parse, layout, render, export) after the renderer has already written partial output to disk, e.g. multi-board render that wrote some boards then failed.

Common situations: Render/export errors mid-multiboard output, interrupted renders leaving stale partial files, plugin failures during the write phase.

Related errors


AI-assisted analysis of d2lang/d2@0d69dca6f5 (2026-08-31). Data as JSON: /api/errors/349b8495d972f8cf. Report an issue: GitHub.