console-table-printer icon indicating copy to clipboard operation
console-table-printer copied to clipboard

Error: Invalid count value when no rows

Open jarrodek opened this issue 3 years ago • 4 comments

The following code fails with the Invalid count value when no rows error.

import { printTable, Table } from 'console-table-printer';

const table = new Table({
  title: 'Project folders',
});
table.printTable();

It looks like the textWithPadding() function in the string-utils file does not handle situation when the size is invalid.

The use case is to print the table header even when there are no items to render.

jarrodek avatar Feb 12 '22 18:02 jarrodek

@jarrodek what is your expected output for this? Why do you want to print only table header?

ayonious avatar Feb 28 '22 16:02 ayonious

Essentially yes. The command in my CLI I am building may not return any results (for example when a query yields no results). The command's output is still the same which is the table but in this specific case, it has no rows. This way the interface stays consistent regardless of the result.

jarrodek avatar Feb 28 '22 17:02 jarrodek

This also fails when the title length > column length.

This works because the title is short

const t = new Table({ title: 'Short'}, columns: ['test'], ['example']);
t.addRow({ test: 1, example: 2 });
t.printTable();

This fails due to the title being longer than the columns

new Table({ title: 'Really long title that is longer than the table itself'}, columns: ['test'], ['example']);
t.addRow({ test: 1, example: 2 });
t.printTable();

Dirrk avatar May 06 '22 23:05 Dirrk

:tada: This issue has been resolved in version 2.11.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

ayonious avatar Aug 24 '22 19:08 ayonious

Seems already been resolved

ayonious avatar Jul 02 '23 19:07 ayonious