Invalid array length
//...
https.get(url, response => {
// if --progress run the progressbar
if (flags.progress) {
const len = parseInt(response.headers['content-length'], 10);
const bar = new ProgressBar(chalk `{yellow ↓} {red :percent} [:bar] :elapsed s`, {
complete: '=',
incomplete: ' ',
width: 20,
total: len,
clear: true
});
// on data received fill the progressbar
response.on('data', chunk => {
bar.tick(chunk.length, {
passphrase: 'Making something awesome'
});
});
}
//... rest of the function
causes:
/Users/rawnly/code/NODE/splash-cli-2018/node_modules/progress/lib/node-progress.js:155
complete = Array(Math.max(0, completeLength + 1)).join(this.chars.complete);
^
RangeError: Invalid array length
at ProgressBar.render (/Users/rawnly/code/NODE/splash-cli-2018/node_modules/progress/lib/node-progress.js:155:14)
at ontimeout (timers.js:471:11)
at tryOnTimeout (timers.js:306:5)
at Timer.listOnTimeout (timers.js:266:5)
Getting this as well
The reason for this problem is probably the total parameter except the problem, the value is NaN, you can check if this is the problem.
Currently experiencing this exact issue.
content-length isn't guaranteed so it could be 0 and make bug. set a value if content-length is 0.
// content-length isn't guaranteed so it could be 0 and make bug. set a value if content-length is 0.
const len = parseInt(response.headers["content-length"], 10) || 100000000;
const bar = new ProgressBar("downloading [:bar] :rate/bps :percent :etas", {
complete: "=",
incomplete: " ",
width: 20,
total: len,
});
response.on("data", (chunk) => {
bar.tick(chunk.length);
});
it need validation for the better error info tips: #171
I confirm the bug in 2.0.3 in case total is 0 :
const ProgressBar = require('progress')
const format = 'progress: :percent [:bar] :current/:total (~:etas left)'
const options = {total: 0}
const progressBar = new ProgressBar(format, options)
// next line throw RangeError: Invalid array length at ProgressBar.render
// on the line `complete = Array(Math.max(0, completeLength + 1)).join(this.chars.complete);`
// because completeLength isn't a number
progressBar.tick(0)
The index of array must be integer. The input :total values is NAN or float, while the output array's index is not integer so than rendering error.
For a temp solution you can change node-progress.js
completeLength = Math.round(width * ratio)
with this one
completeLength = Math.round(width * ratio) | 0;
that works for me
