medikoo/cli-color

es5-ext, cli-color related error

StreetStrider opened this issue · 3 comments

Good day. I have strange error which can only be reproduced in special environment. I've tried to determine the problem myself, but I do not know cli-color and es5-ext packages well enough.

Here's the problem: My project uses console-ultimate package of my own, depends on cli-color (depends on es5-ext). Everything works fine. But when I start project in forever I have constraint error:

RangeError: Count must be >= 0
    at String.module.exports (/home/<project>/opt/<project>/node_modules/console-ultimate/node_modules/cli-color/node_modules/es5-ext/string/#/repeat/shim.js:11:23)
    at Function.module.exports.defineProperties.reset (/home/<project>/opt/<project>/node_modules/console-ultimate/node_modules/cli-color/index.js:109:17)
    at Object.<anonymous> (/home/<project>/opt/<project>/node_modules/console-ultimate/src/console/clear.js:5:30)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/<project>/opt/<project>/node_modules/console-ultimate/src/Console.js:18:10)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
error: Forever detected script exited with code: 8

console-ultimate extensively uses cli-color, but the only feature fails is .clear, I workaround it by removing var reset = require('cli-color').reset in .clear.

This issue reproduces on remote machines with Ubuntu and Centos.

Do you have any ideas why this code fails? Maybe there's conflict in prototypes?

@StreetStrider it looks that height of terminal gets resolved to 0, and that makes repeat to be called with -1.

Still it's only v0.3 where this bug may occur. It's no longer the case with v1 (current version) where reset no longer uses repeat. So best would be if you just upgrade to use cli-color at v1. Mind there are some API changes, but nothing that can't be quickly patched

@medikoo, yes, I know migration would be easy. I'll update and come back with results. Thanks.

've updated flawlessly. Everything works fine. 👍 The issue most probably was caused by redirecting output to file (which is forever do). That caused incorrect terminal size resolution. Thanks for help.