{"record":{"id":"aacbdd97754089bc","repo":"d2lang/d2","slug":"actors-in-sequence-diagrams-cannot-themselves-be-s","errorCode":null,"errorMessage":"actors in sequence diagrams cannot themselves be sequence diagrams: %s","messagePattern":"actors in sequence diagrams cannot themselves be sequence diagrams: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2layouts/d2sequence/sequence_diagram.go","lineNumber":103,"sourceCode":"\tslices.SortFunc(messages, func(a, b *d2graph.Edge) int {\n\t\treturn cmp.Compare(getEdgeEarliestLineNum(a), getEdgeEarliestLineNum(b))\n\t})\n\n\tfor _, obj := range objects {\n\t\tif obj.IsSequenceDiagramGroup() {\n\t\t\tqueue := []*d2graph.Object{obj}\n\t\t\t// Groups may have more nested groups\n\t\t\tfor len(queue) > 0 {\n\t\t\t\tcurr := queue[0]\n\t\t\t\tcurr.LabelPosition = go2.Pointer(label.InsideTopLeft.String())\n\t\t\t\tgroups = append(groups, curr)\n\t\t\t\tqueue = queue[1:]\n\t\t\t\tqueue = append(queue, curr.ChildrenArray...)\n\t\t\t}\n\t\t} else {\n\t\t\tactors = append(actors, obj)\n\t\t\tif obj.IsSequenceDiagram() {\n\t\t\t\treturn nil, fmt.Errorf(\"actors in sequence diagrams cannot themselves be sequence diagrams: %s\", obj.AbsID())\n\t\t\t}\n\t\t}\n\t}\n\n\tif len(actors) == 0 {\n\t\treturn nil, errors.New(\"no actors declared in sequence diagram\")\n\t}\n\n\tsd := &sequenceDiagram{\n\t\tmessages:        messages,\n\t\tactors:          actors,\n\t\tgroups:          groups,\n\t\tspans:           nil,\n\t\tnotes:           nil,\n\t\tlifelines:       nil,\n\t\tobjectRank:      make(map[*d2graph.Object]int),\n\t\tfirstMessage:    make(map[*d2graph.Object]*d2graph.Edge),\n\t\tlastMessage:     make(map[*d2graph.Object]*d2graph.Edge),","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2layouts/d2sequence/sequence_diagram.go#L85-L121","documentation":"While building a sequence diagram's actor list, newSequenceDiagram walks the graph and if an actor object is itself a sequence diagram, the layout cannot be computed. The error reports the offending actor's absolute ID.","triggerScenarios":"Declaring a nested sequence diagram (a board/shape with inner children that form a sequence diagram) inside the actors of another sequence diagram in a D2 script, then running layoutSequenceDiagram.","commonSituations":"Authoring D2 diagrams where a sequence diagram's participant shape is itself given sequence-diagram children (actor-in-actor nesting); accidental indentation creating nested sequence blocks.","solutions":["Move the inner sequence diagram out of the actor list (make it a sibling, not a child of an actor)","Convert the inner sequence diagram to a plain shape or a separate board","Flatten the nesting by declaring the messages between top-level actors instead"],"exampleFix":"// before\nx: shape sequence_diagram {\n  y -> z\n}\nx.y -> x.z\n// after\nx: shape sequence_diagram\ny: shape sequence_diagram { a -> b }","handlingStrategy":"validation","validationCode":"for _, actor := range actors {\n\tif actor.IsSequenceDiagram() {\n\t\treturn fmt.Errorf(\"actor %s is itself a sequence diagram\", actor.AbsID())\n\t}\n}","typeGuard":null,"tryCatchPattern":"_, err := d2lib.Compile(ctx, input, opts)\nif err != nil && strings.Contains(err.Error(), \"cannot themselves be sequence diagrams\") {\n\treturn fmt.Errorf(\"invalid nesting: %w\", err)\n}","preventionTips":["Never declare a sequence diagram inside an actor of another sequence diagram","Keep nested sequence diagrams as sibling boards or separate shapes","Review indentation in D2 scripts — accidental nesting changes semantics"],"tags":["d2","sequence-diagram","nesting","unsupported"],"backgroundTag":"nested-sequence-diagram","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}