{"record":{"id":"d0c6dd99a369d400","repo":"d2lang/d2","slug":"s-is-not-a-supported-format-supported-formats-ar","errorCode":null,"errorMessage":"%s is not a supported format. Supported formats are: %s","messagePattern":"(.+?) is not a supported format\\. Supported formats are: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2cli/export.go","lineNumber":38,"sourceCode":"var STDOUT_FORMAT_MAP = map[string]exportExtension{\n\t\"png\":   PNG,\n\t\"svg\":   SVG,\n\t\"ascii\": TXT,\n\t\"txt\":   TXT,\n\t\"pdf\":   PDF,\n\t\"pptx\":  PPTX,\n\t\"gif\":   GIF,\n}\n\nvar SUPPORTED_STDOUT_FORMATS = []string{\"png\", \"svg\", \"ascii\", \"txt\", \"pdf\", \"pptx\", \"gif\"}\n\nfunc getOutputFormat(stdoutFormatFlag *string, outputPath string) (exportExtension, error) {\n\tif stdoutFormatFlag != nil && *stdoutFormatFlag != \"\" {\n\t\tformat := strings.ToLower(*stdoutFormatFlag)\n\t\tif ext, ok := STDOUT_FORMAT_MAP[format]; ok {\n\t\t\treturn ext, nil\n\t\t}\n\t\treturn \"\", fmt.Errorf(\"%s is not a supported format. Supported formats are: %s\", *stdoutFormatFlag, SUPPORTED_STDOUT_FORMATS)\n\t}\n\treturn getExportExtension(outputPath), nil\n}\n\nfunc getExportExtension(outputPath string) exportExtension {\n\text := filepath.Ext(outputPath)\n\tfor _, kext := range SUPPORTED_EXTENSIONS {\n\t\tif kext == exportExtension(ext) {\n\t\t\treturn exportExtension(ext)\n\t\t}\n\t}\n\t// default is svg\n\treturn exportExtension(SVG)\n}\n\nfunc (ex exportExtension) supportsAnimation() bool {\n\treturn ex == SVG || ex == GIF\n}","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2cli/export.go#L20-L56","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use one of the supported stdout formats (e.g. svg, png, txt/ascii, d2) — the error message lists them","Remove the --format flag and let it be derived from the output file extension","Check the flag value for typos and case (input is lowercased but must match a known key)"],"exampleFix":"// before\nd2 --format jpg input.d2\n// after\nd2 --format png input.d2   # or: d2 input.d2 out.svg","handlingStrategy":"validation","validationCode":"var supported = map[string]bool{\"svg\":true,\"png\":true,\"txt\":true,\"d2\":true} // keys of STDOUT_FORMAT_MAP\nif !supported[strings.ToLower(flagValue)] {\n    return errors.New(\"unsupported stdout format: \"+flagValue)\n}","typeGuard":null,"tryCatchPattern":"ext, err := getOutputFormat(f, path)\nif err != nil {\n    fmt.Fprintf(os.Stderr, \"%v\\n\", err) // message lists supported formats\n    os.Exit(2)\n}","preventionTips":["Check SUPPORTED_STDOUT_FORMATS before setting the --format flag","Derive format from output file extension when possible","Lowercase and trim the flag value in wrapper scripts"],"tags":["go","cli","format","validation"],"backgroundTag":"unsupported-output-format","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}