{"record":{"id":"52a73c8fb65f5d5c","repo":"d2lang/d2","slug":"decode-icon-url-for-stable-diagram-hash-w","errorCode":null,"errorMessage":"decode icon URL for stable diagram hash: %w","messagePattern":"decode icon URL for stable diagram hash: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2target/d2target.go","lineNumber":281,"sourceCode":"\t\t\t\t}\n\t\t\t\tkey, ok := keyToken.(string)\n\t\t\t\tif !ok {\n\t\t\t\t\treturn fmt.Errorf(\"decode diagram hash JSON: object key has type %T\", keyToken)\n\t\t\t\t}\n\t\t\t\tif key != \"icon\" {\n\t\t\t\t\tif err := walkValue(); err != nil {\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tvalueStart, err := hashJSONValueStart(b, int(dec.InputOffset()))\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tvar raw json.RawMessage\n\t\t\t\tif err := dec.Decode(&raw); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"decode icon URL for stable diagram hash: %w\", err)\n\t\t\t\t}\n\t\t\t\tif bytes.Equal(raw, []byte(\"null\")) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tstable, err := stableHashURL(raw)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tvalueEnd := int(dec.InputOffset())\n\t\t\t\tif valueEnd < valueStart || valueEnd > len(b) {\n\t\t\t\t\treturn fmt.Errorf(\"decode icon URL for stable diagram hash: invalid offsets %d:%d\", valueStart, valueEnd)\n\t\t\t\t}\n\t\t\t\tout.Write(b[lastWrite:valueStart])\n\t\t\t\tout.Write(stable)\n\t\t\t\tlastWrite = valueEnd\n\t\t\t}\n\t\t\tcloseToken, err := dec.Token()","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2target/d2target.go#L263-L299","documentation":"When a JSON key equal to \"icon\" is found during stable hashing, the walker decodes its raw value to canonicalize the URL. If json.Decode of the raw value fails, this wrapped error is returned. It indicates the icon field's value cannot be decoded from the surrounding JSON stream.","triggerScenarios":"Stable-hashing diagram JSON whose \"icon\" value sits at an invalid position in the stream (corrupt or truncated JSON), or JSON produced with encoding the decoder cannot handle at that offset.","commonSituations":"Manually edited diagram JSON; partial writes to cached diagram files; mixing JSON from incompatible d2 versions.","solutions":["Validate the JSON is well-formed with json.Valid before hashing","Re-serialize the diagram from the in-memory d2target.Diagram","Ensure the \"icon\" key holds a JSON string URL, not some other malformed value"],"exampleFix":"// before\nhash, _ := StableHashWithIcons(brokenJSON)\n// after\nif !json.Valid(brokenJSON) { return errors.New(\"bad json\") }\nhash, _ := StableHashWithIcons(brokenJSON)","handlingStrategy":"validation","validationCode":"if !json.Valid(b) {\n\treturn errors.New(\"diagram JSON is malformed\")\n}","typeGuard":null,"tryCatchPattern":"out, err := StableHashWithIcons(b)\nif err != nil {\n\t// fallback: hash without icon canonicalization or re-marshal diagram\n}","preventionTips":["Ensure the \"icon\" field holds a JSON string URL","Validate JSON before hashing","Regenerate diagram JSON from the compiled diagram on failure"],"tags":["json","hashing","icons"],"backgroundTag":"json-decode-failure","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}