{"record":{"id":"085d96f4bb57cdd1","repo":"d2lang/d2","slug":"dimensions-for-sql-table-name-v-not-found","errorCode":null,"errorMessage":"dimensions for sql_table name %#v not found","messagePattern":"dimensions for sql_table name %#v not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2graph/d2graph.go","lineNumber":1099,"sourceCode":"\tcase d2target.ShapeSQLTable:\n\t\tmaxNameWidth := 0\n\t\tmaxTypeWidth := 0\n\t\tmaxConstraintWidth := 0\n\n\t\tcolFontSize := d2fonts.FONT_SIZE_L\n\t\tif obj.Style.FontSize != nil {\n\t\t\tcolFontSize, _ = strconv.Atoi(obj.Style.FontSize.Value)\n\t\t}\n\n\t\tfor i := range obj.SQLTable.Columns {\n\t\t\t// Note: we want to set dimensions of actual column not the for loop copy of the struct\n\t\t\tc := &obj.SQLTable.Columns[i]\n\n\t\t\tctexts := c.Texts(colFontSize)\n\n\t\t\tnameDims := GetTextDimensions(mtexts, ruler, ctexts[0], fontFamily)\n\t\t\tif nameDims == nil {\n\t\t\t\treturn nil, fmt.Errorf(\"dimensions for sql_table name %#v not found\", ctexts[0].Text)\n\t\t\t}\n\t\t\tc.Name.LabelWidth = nameDims.Width\n\t\t\tc.Name.LabelHeight = nameDims.Height\n\t\t\tmaxNameWidth = go2.Max(maxNameWidth, nameDims.Width)\n\n\t\t\ttypeDims := GetTextDimensions(mtexts, ruler, ctexts[1], fontFamily)\n\t\t\tif typeDims == nil {\n\t\t\t\treturn nil, fmt.Errorf(\"dimensions for sql_table type %#v not found\", ctexts[1].Text)\n\t\t\t}\n\t\t\tc.Type.LabelWidth = typeDims.Width\n\t\t\tc.Type.LabelHeight = typeDims.Height\n\t\t\tmaxTypeWidth = go2.Max(maxTypeWidth, typeDims.Width)\n\n\t\t\tif l := len(c.Constraint); l > 0 {\n\t\t\t\tconstraintDims := GetTextDimensions(mtexts, ruler, ctexts[2], fontFamily)\n\t\t\t\tif constraintDims == nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"dimensions for sql_table constraint %#v not found\", ctexts[2].Text)\n\t\t\t\t}","sourceCodeStart":1081,"sourceCodeEnd":1117,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2graph/d2graph.go#L1081-L1117","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a non-nil, initialized textmeasure.Ruler to SetDimensions","Ensure mtexts includes all sql_table column name texts (regenerate via graph.SetText)","Verify the configured font family is fully loaded in the ruler (see HasFontFamilyLoaded)","Avoid editing SQLTable columns after measurement texts are built"],"exampleFix":"// before\nerr := graph.SetDimensions(mtexts, nil, fontFamily, mono)\n// after\nruler, _ := textmeasure.NewRuler()\nerr := graph.SetDimensions(mtexts, ruler, fontFamily, mono)","handlingStrategy":"validation","validationCode":"ruler, _ := textmeasure.NewRuler()\nruler.InitFonts(d2fonts.D2Fonts)\nfor _, obj := range graph.Objects {\n    if obj.SQLTable != nil {\n        for _, c := range obj.SQLTable.Columns {\n            txt := c.Texts(d2fonts.DEFAULT_FONT_SIZE)[0].Text\n            found := false\n            for _, mt := range mtexts { if mt.Text == txt { found = true; break } }\n            if !found { return fmt.Errorf(\"unmeasured sql_table column name: %q\", txt) }\n        }\n    }\n}","typeGuard":"func sqlTableNamesMeasured(obj *d2graph.Object, mtexts []*d2target.MText) bool {\n    if obj.SQLTable == nil { return true }\n    for _, c := range obj.SQLTable.Columns {\n        txt := c.Texts(d2fonts.DEFAULT_FONT_SIZE)[0].Text\n        found := false\n        for _, mt := range mtexts { if mt.Text == txt { found = true; break } }\n        if !found { return false }\n    }\n    return true\n}","tryCatchPattern":"if err := graph.SetDimensions(mtexts, ruler, fontFamily, mono); err != nil {\n    if strings.Contains(err.Error(), \"dimensions for sql_table name\") {\n        mtexts = graph.SetText(ruler, fontFamily)\n        err = graph.SetDimensions(mtexts, ruler, fontFamily, mono)\n    }\n    return err\n}","preventionTips":["Regenerate mtexts after adding or renaming sql_table columns","Pass a non-nil ruler whenever the graph contains sql_table shapes","Verify font family coverage with ruler.HasFontFamilyLoaded before sizing","Build tables via the d2 compile flow so texts are auto-registered"],"tags":["go","d2","text-measurement","sql-table"],"backgroundTag":"text-dimensions-not-found","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}