d2lang/d2 · error

%s is not a supported format. Supported formats are: %s

Error message

%s is not a supported format. Supported formats are: %s

What it means

getOutputFormat validates the --format flag against STDOUT_FORMAT_MAP. If the user requests a stdout format the tool does not know, it returns the unsupported-format error listing the supported values.

Source

Thrown at d2cli/export.go:38

var STDOUT_FORMAT_MAP = map[string]exportExtension{
	"png":   PNG,
	"svg":   SVG,
	"ascii": TXT,
	"txt":   TXT,
	"pdf":   PDF,
	"pptx":  PPTX,
	"gif":   GIF,
}

var SUPPORTED_STDOUT_FORMATS = []string{"png", "svg", "ascii", "txt", "pdf", "pptx", "gif"}

func getOutputFormat(stdoutFormatFlag *string, outputPath string) (exportExtension, error) {
	if stdoutFormatFlag != nil && *stdoutFormatFlag != "" {
		format := strings.ToLower(*stdoutFormatFlag)
		if ext, ok := STDOUT_FORMAT_MAP[format]; ok {
			return ext, nil
		}
		return "", fmt.Errorf("%s is not a supported format. Supported formats are: %s", *stdoutFormatFlag, SUPPORTED_STDOUT_FORMATS)
	}
	return getExportExtension(outputPath), nil
}

func getExportExtension(outputPath string) exportExtension {
	ext := filepath.Ext(outputPath)
	for _, kext := range SUPPORTED_EXTENSIONS {
		if kext == exportExtension(ext) {
			return exportExtension(ext)
		}
	}
	// default is svg
	return exportExtension(SVG)
}

func (ex exportExtension) supportsAnimation() bool {
	return ex == SVG || ex == GIF
}

View on GitHub (pinned to 0d69dca6f5)

Solutions

  1. Use one of the supported stdout formats (e.g. svg, png, txt/ascii, d2) — the error message lists them
  2. Remove the --format flag and let it be derived from the output file extension
  3. Check the flag value for typos and case (input is lowercased but must match a known key)

Example fix

// before
d2 --format jpg input.d2
// after
d2 --format png input.d2   # or: d2 input.d2 out.svg
Defensive patterns

Strategy: validation

Validate before calling

var supported = map[string]bool{"svg":true,"png":true,"txt":true,"d2":true} // keys of STDOUT_FORMAT_MAP
if !supported[strings.ToLower(flagValue)] {
    return errors.New("unsupported stdout format: "+flagValue)
}

Try / catch

ext, err := getOutputFormat(f, path)
if err != nil {
    fmt.Fprintf(os.Stderr, "%v\n", err) // message lists supported formats
    os.Exit(2)
}

Prevention

When it happens

Trigger: Running d2 with a --format flag value that is not in STDOUT_FORMAT_MAP, e.g. 'd2 --format jpg file.d2' or an empty/mistyped format string.

Common situations: Typos in the format flag, expecting an export format (like jpg) to also be valid for stdout, or scripts passing a variable format from config.

Related errors


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