larswaechter / voici.js

A Node.js library for pretty printing your data on the terminal🎨
https://voici.larswaechter.dev
MIT License
335 stars 4 forks source link

JS error when the terminal width is short #20

Closed Jinjiang closed 1 year ago

Jinjiang commented 1 year ago

Reproduce:

https://github.com/Jinjiang/reproductions/tree/voici-20230503

I guess the trigger is when the header name of a column is longer than its content.

The error log:

/Users/....../reproductions/node_modules/.pnpm/voici.js@2.0.0/node_modules/voici.js/dist/table.js:173
        return this.config.padding.char.repeat(size);
                                        ^

RangeError: Invalid count value
    at String.repeat (<anonymous>)
    at Table.getPadding (/Users/....../reproductions/node_modules/.pnpm/voici.js@2.0.0/node_modules/voici.js/dist/table.js:173:41)
    at Table.buildCellContent (/Users/....../reproductions/node_modules/.pnpm/voici.js@2.0.0/node_modules/voici.js/dist/table.js:348:54)
    at Table.buildHeaderCell (/Users/....../reproductions/node_modules/.pnpm/voici.js@2.0.0/node_modules/voici.js/dist/table.js:487:32)
    at Table.buildHeader (/Users/....../reproductions/node_modules/.pnpm/voici.js@2.0.0/node_modules/voici.js/dist/table.js:501:40)
    at Table.toString (/Users/....../reproductions/node_modules/.pnpm/voici.js@2.0.0/node_modules/voici.js/dist/table.js:96:22)
    at Table.print (/Users/....../reproductions/node_modules/.pnpm/voici.js@2.0.0/node_modules/voici.js/dist/table.js:121:26)
    at Object.<anonymous> (/Users/....../reproductions/index.js:18:7)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)

Thanks.

larswaechter commented 1 year ago

Hi @Jinjiang,

thanks for your feedback! I was able to reproduce your error. Seems like it crashes when the terminal's window width isn't big enough and a header name tries to overflow in the next row. I'll take a look on it.

larswaechter commented 1 year ago

Will be fixed in #22.