grunt icon indicating copy to clipboard operation
grunt copied to clipboard

Grunt task max characters 76 in lib/grunt/help.js

Open zgardner opened this issue 10 years ago • 2 comments

I have a registered task whose length is 90 characters. After I register it, the grunt --help command freezes, and eventually gives me a GC exception because it ran out of memory. This is why it is happening. (Note: I'm on Grunt 0.4.5 on Windows 7.)

In lib/grunt/help.js, the exports.display method iterates over several methods to get help ready to display. The first method is initOptions, which calls initCol1, which updates the col1len variable to be the length of the longest task. The third method is initWidths, which uses col1len to set exports.widths to an array. The value for the last element in the array is 76 - col1len. Because my col1len is 90, the value for the fourth width is -14.

Eventually the options method is called, which calls exports.table, which uses exports.widths to write out the given task. It passes it to grunt.log.writetableln, and this seems to be where the script freezes.

If I increase the 76 to a value like 100, the grunt --help command runs.

I am not sure the proper place to fix this in the grunt code. Is the maximum length of a task name well documented? I did a quick search, and did not find anything.

I think one of the following should fix this:

  1. Use Math.max(0, 76 - col1len) when calculating the fourth element in the array as a sanity check.
  2. Update grunt.log.writeableln to not freak out when passing it a negative value for the fourth element in the array.
  3. Throw an exception when a task is registered whose number of characters exceeds the maximum value.

zgardner avatar Oct 26 '15 10:10 zgardner

The problem with "grunt.log.writeableln" is in another repository. The maximum length for task name isn't documented. (After a quick search too :tongue:)

tomapp avatar Nov 29 '15 00:11 tomapp

LG2M.

zgardner avatar Nov 30 '15 11:11 zgardner