d2lang/d2 · error
dimensions for sql_table type %#v not found
Error message
dimensions for sql_table type %#v not found
What it means
During sql_table sizing, each column's type text (ctexts[1]) is measured after the name. A nil result means the type label was neither pre-measured in mtexts nor measurable by the ruler, so the table's column widths cannot be computed and rendering aborts.
Source
Thrown at d2graph/d2graph.go:1107
}
for i := range obj.SQLTable.Columns {
// Note: we want to set dimensions of actual column not the for loop copy of the struct
c := &obj.SQLTable.Columns[i]
ctexts := c.Texts(colFontSize)
nameDims := GetTextDimensions(mtexts, ruler, ctexts[0], fontFamily)
if nameDims == nil {
return nil, fmt.Errorf("dimensions for sql_table name %#v not found", ctexts[0].Text)
}
c.Name.LabelWidth = nameDims.Width
c.Name.LabelHeight = nameDims.Height
maxNameWidth = go2.Max(maxNameWidth, nameDims.Width)
typeDims := GetTextDimensions(mtexts, ruler, ctexts[1], fontFamily)
if typeDims == nil {
return nil, fmt.Errorf("dimensions for sql_table type %#v not found", ctexts[1].Text)
}
c.Type.LabelWidth = typeDims.Width
c.Type.LabelHeight = typeDims.Height
maxTypeWidth = go2.Max(maxTypeWidth, typeDims.Width)
if l := len(c.Constraint); l > 0 {
constraintDims := GetTextDimensions(mtexts, ruler, ctexts[2], fontFamily)
if constraintDims == nil {
return nil, fmt.Errorf("dimensions for sql_table constraint %#v not found", ctexts[2].Text)
}
maxConstraintWidth = go2.Max(maxConstraintWidth, constraintDims.Width)
}
}
// The rows get padded a little due to header font being larger than row font
dims.Height = go2.Max(12, labelDims.Height*(len(obj.SQLTable.Columns)+1))
headerWidth := d2target.HeaderPadding + labelDims.Width + d2target.HeaderPadding
rowsWidth := d2target.NamePadding + maxNameWidth + d2target.TypePadding + maxTypeWidth + d2target.TypePadding + maxConstraintWidthView on GitHub (pinned to 0d69dca6f5)
Solutions
- Provide an initialized textmeasure.Ruler so types are measured on demand
- Regenerate mtexts via graph.SetText after changing column types
- Confirm the font family used for table text is loaded into the ruler
- Treat sql_table columns as immutable between measurement and SetDimensions
Example fix
// before dims := GetTextDimensions(mtexts, nil, ctexts[1], fontFamily) // nil without ruler // after ruler, _ := textmeasure.NewRuler() dims := GetTextDimensions(mtexts, ruler, ctexts[1], fontFamily)
Defensive patterns
Strategy: validation
Validate before calling
ruler, _ := textmeasure.NewRuler()
ruler.InitFonts(d2fonts.D2Fonts)
for _, obj := range graph.Objects {
if obj.SQLTable != nil {
for _, c := range obj.SQLTable.Columns {
typeText := c.Texts(d2fonts.DEFAULT_FONT_SIZE)[1].Text
found := false
for _, mt := range mtexts { if mt.Text == typeText { found = true; break } }
if !found { return fmt.Errorf("unmeasured sql_table type: %q", typeText) }
}
}
} Type guard
func sqlTableTypesMeasured(obj *d2graph.Object, mtexts []*d2target.MText) bool {
if obj.SQLTable == nil { return true }
for _, c := range obj.SQLTable.Columns {
txt := c.Texts(d2fonts.DEFAULT_FONT_SIZE)[1].Text
found := false
for _, mt := range mtexts { if mt.Text == txt { found = true; break } }
if !found { return false }
}
return true
} Try / catch
if err := graph.SetDimensions(mtexts, ruler, fontFamily, mono); err != nil {
if strings.Contains(err.Error(), "dimensions for sql_table type") {
mtexts = graph.SetText(ruler, fontFamily)
err = graph.SetDimensions(mtexts, ruler, fontFamily, mono)
}
return err
} Prevention
- Treat column types as immutable between text measurement and SetDimensions
- Regenerate mtexts whenever column type strings change
- Use a font-loaded ruler so on-demand measurement is always possible
- Prefer the standard d2 compile pipeline over programmatic table construction
When it happens
Trigger: Rendering a sql_table where a column's type string at colFontSize is missing from mtexts and ruler is nil or has no measurement for that text/font/size combination.
Common situations: Column types set programmatically after mtexts generation; embedded usage passing nil ruler; custom fonts not registered; type text mutated between measurement and sizing passes.
Related errors
- dimensions for sql_table name %#v not found
- dimensions for sql_table constraint %#v not found
- dimensions for object label %#v not found
- dimensions for class field %#v not found
- dimensions for class method %#v not found
AI-assisted analysis of d2lang/d2@0d69dca6f5 (2026-08-31).
Data as JSON: /api/errors/2272cca2008522d6.
Report an issue: GitHub.