Closed robertjli closed 1 year ago
If a column has a format string, and a row is missing data in that column, an unexpected error is shown.
table.New([]table.Column{ table.NewColumn(columnKeyName, "Name", 13), table.NewColumn(columnKeyElement, "Element", 10), table.NewColumn(columnKeyHeight, "Height", 16).WithFormatString("%.2f m"), }).WithRows([]table.Row{ table.NewRow(table.RowData{ columnKeyName: "Pikachu", columnKeyElement: "Electric", // height is missing }), table.NewRow(table.RowData{ columnKeyName: "Charmander", columnKeyElement: "Fire", columnKeyHeight: 0.6, }), })
┏━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓ ┃ Name┃ Element┃ Height┃ ┣━━━━━━━━━━━━━╋━━━━━━━━━━╋━━━━━━━━━━━━━━━━┫ ┃ Pikachu┃ Electric┃ %!f(string=) m┃ ┃ Charmander┃ Fire┃ 0.60 m┃ ┗━━━━━━━━━━━━━┻━━━━━━━━━━┻━━━━━━━━━━━━━━━━┛
This PR fixes the bug by only setting the format string if data exists.
If a column has a format string, and a row is missing data in that column, an unexpected error is shown.
This PR fixes the bug by only setting the format string if data exists.