{"record":{"id":"2737fb0cad115b88","repo":"d2lang/d2","slug":"spaces-are-not-allowed-in-blockstring-tags","errorCode":null,"errorMessage":"spaces are not allowed in blockstring tags","messagePattern":"spaces are not allowed in blockstring tags","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2oracle/edit.go","lineNumber":330,"sourceCode":"\treturn pathFromScopeKey(g, key, scopeak)\n}\n\nfunc recompile(g *d2graph.Graph) (*d2graph.Graph, error) {\n\ts := d2format.Format(g.AST)\n\tg2, _, err := d2compiler.Compile(g.AST.Range.Path, strings.NewReader(s), &d2compiler.CompileOptions{\n\t\tFS: g.FS,\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to recompile:\\n%s\\n%w\", s, err)\n\t}\n\treturn g2, nil\n}\n\n// TODO merge flat styles\nfunc _set(g *d2graph.Graph, baseAST *d2ast.Map, key string, tag, value *string) error {\n\tif tag != nil {\n\t\tif hasSpace(*tag) {\n\t\t\treturn fmt.Errorf(\"spaces are not allowed in blockstring tags\")\n\t\t}\n\t}\n\n\tmk, err := d2parser.ParseMapKey(key)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif len(mk.Edges) > 1 {\n\t\treturn errors.New(\"can only set one edge at a time\")\n\t}\n\n\tif value != nil {\n\t\tmk.Value = d2ast.MakeValueBox(d2ast.RawString(*value, false))\n\t} else {\n\t\tmk.Value = d2ast.ValueBox{}\n\t}\n\tif tag != nil && value != nil {","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2oracle/edit.go#L312-L348","documentation":"In _set, when a blockstring tag is provided (tag != nil), it must not contain whitespace because tags become part of the blockstring delimiter (e.g. |`tag ... tag`|). Set rejects a tag containing any space with this error before parsing the key.","triggerScenarios":"Calling Set(g, boardPath, key, tag, value) where *tag contains a space character, as detected by hasSpace — e.g. tag := ptr(\"my tag\").","commonSituations":"Building blockstring tags from user input or labels with spaces; forgetting that D2 blockstring tags must be a single token.","solutions":["Strip or replace whitespace in the tag before calling Set (e.g. camelCase, kebab-case, or underscore).","Pass tag = nil if no blockstring tag is needed.","Validate the tag with strings.ContainsFunc(tag, unicode.IsSpace) before the call."],"exampleFix":"// before\ntag := \"sql query\"\ng2, err := d2oracle.Set(g, nil, \"desc\", &tag, &val) // error\n// after\ntag := \"sql-query\"\ng2, err := d2oracle.Set(g, nil, \"desc\", &tag, &val)","handlingStrategy":"validation","validationCode":"func validTag(tag *string) bool {\n    return tag == nil || !strings.ContainsFunc(*tag, unicode.IsSpace)\n}","typeGuard":"func sanitizeTag(tag string) string {\n    return strings.Join(strings.Fields(tag), \"-\")\n}","tryCatchPattern":"if err := d2oracle.Set(g, boardPath, key, &tag, &value); err != nil &&\n    strings.Contains(err.Error(), \"spaces are not allowed in blockstring tags\") {\n    t := sanitizeTag(tag)\n    g2, err = d2oracle.Set(g, boardPath, key, &t, &value)\n}","preventionTips":["Sanitize user-supplied tags: replace whitespace with '-' or '_'","Pass nil tag when no blockstring is intended","Unit-test tag inputs containing spaces"],"tags":["go","d2","blockstring","validation"],"backgroundTag":"invalid-blockstring-tag","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}