{"record":{"id":"a486025aeecad3dc","repo":"d2lang/d2","slug":"unknown-svg-path-command-s","errorCode":null,"errorMessage":"unknown svg path command \"%s\"","messagePattern":"unknown svg path command \"(.+?)\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/svg/path.go","lineNumber":161,"sourceCode":"\t\tY: (u1*u1*u1)*p1.Y + (3*t1*u1*u1)*p2.Y + (3*t1*t1*u1)*p3.Y + t1*t1*t1*p4.Y,\n\t}\n\n\treturn q1, q2, q3, q4\n}\n\n// Gets a certain line/curve's SVG path string. offsetIdx and pathData provides the points needed\nfunc getSVGPathString(pathType string, offsetIdx int, pathData []string) (string, error) {\n\tswitch pathType {\n\tcase \"M\":\n\t\treturn fmt.Sprintf(\"M %s %s \", pathData[offsetIdx+1], pathData[offsetIdx+2]), nil\n\tcase \"L\":\n\t\treturn fmt.Sprintf(\"L %s %s \", pathData[offsetIdx+1], pathData[offsetIdx+2]), nil\n\tcase \"C\":\n\t\treturn fmt.Sprintf(\"C %s %s %s %s %s %s \", pathData[offsetIdx+1], pathData[offsetIdx+2], pathData[offsetIdx+3], pathData[offsetIdx+4], pathData[offsetIdx+5], pathData[offsetIdx+6]), nil\n\tcase \"S\":\n\t\treturn fmt.Sprintf(\"S %s %s %s %s \", pathData[offsetIdx+1], pathData[offsetIdx+2], pathData[offsetIdx+3], pathData[offsetIdx+4]), nil\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"unknown svg path command \\\"%s\\\"\", pathData[offsetIdx])\n\t}\n}\n\n// Gets how much to increment by on an SVG string to get to the next path command\nfunc getPathStringIncrement(pathType string) (int, error) {\n\tswitch pathType {\n\tcase \"M\":\n\t\treturn 3, nil\n\tcase \"L\":\n\t\treturn 3, nil\n\tcase \"C\":\n\t\treturn 7, nil\n\tcase \"S\":\n\t\treturn 5, nil\n\tdefault:\n\t\treturn 0, fmt.Errorf(\"unknown svg path command \\\"%s\\\"\", pathType)\n\t}\n}","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/lib/svg/path.go#L143-L179","documentation":"getSVGPathString reconstructs a command substring for a tokenized SVG path; it only supports M, L, C, and S commands, and returns this error for any other command token encountered in pathData. It means the path uses an SVG command the splitter does not implement.","triggerScenarios":"SplitPath (directly or via pathLength/getPathStringIncrement) on a path whose d attribute contains commands like A (arc), Q/T (quadratic), H/V, or Z, which have no case in the switch.","commonSituations":"Diagrams or exported SVGs produced by tools that emit arcs (A) for rounded shapes or quadratic curves (Q/T); hand-written SVG with H/V relative commands.","solutions":["Preprocess the SVG to convert unsupported commands (A→C arc flattening, Q/T→C, H/V→L) before splitting","Normalize the path with an SVG path normalizer library","Regenerate the diagram with settings that emit only cubic/line commands","Extend the switch in lib/svg/path.go to handle the missing command","Check the raw d attribute to confirm which command triggered it"],"exampleFix":"// before: path d=\"M0 0 A5 5 0 0 1 10 10\" → error\n// after: convert arcs to cubics before splitting\nd = normalizeSVGPath(d) // A commands flattened to C\nfirst, second, err := svg.SplitPath(d)","handlingStrategy":"validation","validationCode":"func hasOnlySupportedCmds(d string) bool {\n    for _, tok := range strings.Fields(d) {\n        if len(tok) == 1 && strings.Contains(\"AQTHVZ\"+strings.ToLower(\"AQTHVZ\"), tok) { return false }\n    }\n    return true\n}","typeGuard":"func isUnsupportedCmdErr(err error) bool { return strings.HasPrefix(err.Error(), \"unknown svg path command\") }","tryCatchPattern":"first, second, err := svg.SplitPath(pathData)\nif err != nil && isUnsupportedCmdErr(err) {\n    pathData = strings.Fields(normalizeToCubics(strings.Join(pathData, \" \")))\n    first, second, err = svg.SplitPath(pathData)\n}","preventionTips":["Normalize SVG paths to M/L/C/S before processing","Flatten arcs and quadratic curves on import","Sanitize user-supplied SVG assets","Test against SVGs from all supported exporters"],"tags":["go","svg","path-parsing","unsupported-command"],"backgroundTag":"unsupported-svg-path-command","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}