{"record":{"id":"16fa85d8b3e4c444","repo":"charmbracelet/gum","slug":"invalid-number-of-columns","errorCode":null,"errorMessage":"invalid number of columns","messagePattern":"invalid number of columns","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"table/command.go","lineNumber":94,"sourceCode":"\t\tcolumns = append(columns, table.Column{\n\t\t\tTitle: title,\n\t\t\tWidth: width,\n\t\t})\n\t}\n\n\tdefaultStyles := table.DefaultStyles()\n\ttop, right, bottom, left := style.ParsePadding(o.Padding)\n\n\tstyles := table.Styles{\n\t\tCell:     defaultStyles.Cell.Inherit(o.CellStyle.ToLipgloss()),\n\t\tHeader:   defaultStyles.Header.Inherit(o.HeaderStyle.ToLipgloss()),\n\t\tSelected: o.SelectedStyle.ToLipgloss(),\n\t}\n\n\trows := make([]table.Row, 0, len(data))\n\tfor row := range data {\n\t\tif len(data[row]) > len(columns) {\n\t\t\treturn fmt.Errorf(\"invalid number of columns\")\n\t\t}\n\n\t\t// fixes the data in case we have more columns than rows:\n\t\tfor len(data[row]) < len(columns) {\n\t\t\tdata[row] = append(data[row], \"\")\n\t\t}\n\n\t\tfor i, col := range data[row] {\n\t\t\tif len(o.Widths) == 0 {\n\t\t\t\twidth := lipgloss.Width(col)\n\t\t\t\tif width > columns[i].Width {\n\t\t\t\t\tcolumns[i].Width = width\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\trows = append(rows, table.Row(data[row]))\n\t}","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/charmbracelet/gum/blob/4d089f95507708a71f64dacfe7ca513219dd5267/table/command.go#L76-L112","documentation":"gum table rejects rows that contain more cells than the declared number of columns, since there is no header/style entry to render the extra cells. Rows with fewer cells are padded with empty strings, but extra columns are an unrecoverable mismatch. The library throws this instead of silently dropping data.","triggerScenarios":"Running `gum table` where some row in the input has more comma-separated fields than the header/columns list (len(data[row]) > len(columns)).","commonSituations":"CSV rows containing unquoted commas inside values so they split into extra fields; header row edited/shortened while data rows kept the old width; joining data sources with different column counts.","solutions":["Quote fields that contain commas so they don't split into extra columns","Ensure the header row has the same number of fields as every data row","Preprocess the input (e.g. awk/csvkit) to normalize row lengths before piping","Use --columns to explicitly define a header matching the widest row"],"exampleFix":"// before (3 cells vs 2-column header)\necho 'name,age\n\"Doe, John\",30' | gum table\n// after — quoted field stays one cell\necho 'name,age\n\"Doe, John\",30' | gum table  # correct if quoting is preserved","handlingStrategy":"validation","validationCode":"awk -F',' 'NR==1{n=NF;next} NF!=n{print \"row \"NR\" has \"NF\" cols, expected \"n; exit 1}' data.csv","typeGuard":null,"tryCatchPattern":"if ! out=$(gum table < data.csv 2>&1); then\n  echo \"$out\" >&2; exit 1\nfi","preventionTips":["Always quote CSV fields containing commas","Keep header and data rows the same width","Normalize row lengths with a CSV library before piping"],"tags":["csv","table","validation"],"backgroundTag":"column-count-mismatch","analyzedSha":"4d089f95507708a71f64dacfe7ca513219dd5267","analyzedAt":"2026-08-31T18:45:06.436Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}