{"record":{"id":"b1ef84c995563851","repo":"d2lang/d2","slug":"dimensions-for-sql-table-constraint-v-not-found","errorCode":null,"errorMessage":"dimensions for sql_table constraint %#v not found","messagePattern":"dimensions for sql_table constraint %#v not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2graph/d2graph.go","lineNumber":1116,"sourceCode":"\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}\n\t\t\t\tmaxConstraintWidth = go2.Max(maxConstraintWidth, constraintDims.Width)\n\t\t\t}\n\t\t}\n\n\t\t// The rows get padded a little due to header font being larger than row font\n\t\tdims.Height = go2.Max(12, labelDims.Height*(len(obj.SQLTable.Columns)+1))\n\t\theaderWidth := d2target.HeaderPadding + labelDims.Width + d2target.HeaderPadding\n\t\trowsWidth := d2target.NamePadding + maxNameWidth + d2target.TypePadding + maxTypeWidth + d2target.TypePadding + maxConstraintWidth\n\t\tif maxConstraintWidth != 0 {\n\t\t\trowsWidth += d2target.ConstraintPadding\n\t\t}\n\t\tdims.Width = go2.Max(12, go2.Max(headerWidth, rowsWidth))\n\t}\n\n\treturn &dims, nil\n}\n","sourceCodeStart":1098,"sourceCodeEnd":1134,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2graph/d2graph.go#L1098-L1134","documentation":"If a sql_table column declares a constraint (e.g. PRIMARY KEY, NOT NULL), its text (ctexts[2]) must be measured to compute the constraint column width. A nil measurement — not pre-measured and not ruler-measurable — fails the whole sql_table sizing with this error.","triggerScenarios":"Rendering a sql_table with a non-empty column.Constraint whose constraint text at colFontSize is absent from mtexts and cannot be measured (nil ruler or missing measurement).","commonSituations":"Constraints added to columns after mtexts were generated; nil ruler in embedded renderers; custom font family not loaded into ruler; programmatic table construction skipping the measurement pass.","solutions":["Pass a non-nil, font-loaded textmeasure.Ruler to SetDimensions","Regenerate mtexts with graph.SetText after modifying column constraints","Verify the ruler loaded the font family used for constraint text","Build sql_tables through the standard d2 compile flow rather than hand-constructing them"],"exampleFix":"// before\nerr := graph.SetDimensions(mtexts, nil, fontFamily, nil)\n// after\nruler, _ := textmeasure.NewRuler()\nruler.InitFonts(d2fonts.D2Fonts)\nerr := graph.SetDimensions(mtexts, ruler, fontFamily, &d2fonts.SourceCodePro)","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            if c.Constraint == \"\" { continue }\n            txt := c.Texts(d2fonts.DEFAULT_FONT_SIZE)[2].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 constraint: %q\", txt) }\n        }\n    }\n}","typeGuard":"func sqlTableConstraintsMeasured(obj *d2graph.Object, mtexts []*d2target.MText) bool {\n    if obj.SQLTable == nil { return true }\n    for _, c := range obj.SQLTable.Columns {\n        if c.Constraint == \"\" { continue }\n        txt := c.Texts(d2fonts.DEFAULT_FONT_SIZE)[2].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 constraint\") {\n        mtexts = graph.SetText(ruler, fontFamily)\n        err = graph.SetDimensions(mtexts, ruler, fontFamily, mono)\n    }\n    return err\n}","preventionTips":["Add constraints before running the measurement pass, never after","Keep a font-initialized ruler in scope for all SetDimensions calls","Regenerate mtexts after any constraint edit","Test sql_table rendering in CI with constraints to catch stale measurement lists"],"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"}