d2lang/d2 · error

dimensions for sql_table name %#v not found

Error message

dimensions for sql_table name %#v not found

What it means

When sizing a sql_table shape, D2 measures each column's name text (column 0 of the column's texts). If GetTextDimensions returns nil — no pre-measured entry and no ruler measurement — table sizing fails with this error naming the missing column name text.

Source

Thrown at d2graph/d2graph.go:1099

	case d2target.ShapeSQLTable:
		maxNameWidth := 0
		maxTypeWidth := 0
		maxConstraintWidth := 0

		colFontSize := d2fonts.FONT_SIZE_L
		if obj.Style.FontSize != nil {
			colFontSize, _ = strconv.Atoi(obj.Style.FontSize.Value)
		}

		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)
				}

View on GitHub (pinned to 0d69dca6f5)

Solutions

  1. Pass a non-nil, initialized textmeasure.Ruler to SetDimensions
  2. Ensure mtexts includes all sql_table column name texts (regenerate via graph.SetText)
  3. Verify the configured font family is fully loaded in the ruler (see HasFontFamilyLoaded)
  4. Avoid editing SQLTable columns after measurement texts are built

Example fix

// before
err := graph.SetDimensions(mtexts, nil, fontFamily, mono)
// after
ruler, _ := textmeasure.NewRuler()
err := graph.SetDimensions(mtexts, ruler, fontFamily, mono)
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 {
            txt := c.Texts(d2fonts.DEFAULT_FONT_SIZE)[0].Text
            found := false
            for _, mt := range mtexts { if mt.Text == txt { found = true; break } }
            if !found { return fmt.Errorf("unmeasured sql_table column name: %q", txt) }
        }
    }
}

Type guard

func sqlTableNamesMeasured(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)[0].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 name") {
        mtexts = graph.SetText(ruler, fontFamily)
        err = graph.SetDimensions(mtexts, ruler, fontFamily, mono)
    }
    return err
}

Prevention

When it happens

Trigger: Rendering a sql_table whose column name text at colFontSize is not present in mtexts and cannot be measured because ruler is nil or lacks that text/font measurement.

Common situations: SQL table columns added after mtexts were generated; nil ruler in embedded pipelines; custom font family not loaded; schema labels containing characters the configured font can't measure without fallbacks.

Related errors


AI-assisted analysis of d2lang/d2@0d69dca6f5 (2026-08-31). Data as JSON: /api/errors/085d96f4bb57cdd1. Report an issue: GitHub.