zowe-cli icon indicating copy to clipboard operation
zowe-cli copied to clipboard

zos-file invoke ams-file error "Maximum call stack size exceeded"

Open pjfarleyiii opened this issue 3 years ago • 1 comments

Trying to execute an AMS command to display contents of a large catalog generates error "Maximum call stack size exceeded". Response output below.

CMD.EXE environment under Windows 10 Pro Version 21H2 to issue the zowe command. z/OS environment targeted is:

OS version is z/OS 02.04.00 - FMID HBB77C0 (SP7.2.4).

Sample commands:

C:\testdir>zowe --version 6.37.0 C:\testdir>zowe files call af listcat.ams.cat 1>listcat.cat.out

Sample of input AMS file:

  PARM GRAPHICS(CHAIN(TN))
  LISTCAT CATALOG('LARGE.CATALOG') ALL

zowe response:

Unexpected Command Error:
Please review the message and stack below.
Contact the creator of handler:
"C:\Users\localuser\AppData\Roaming\npm\node_modules\@zowe\cli\lib\zosfiles\invoke\amsFile\AmsFile.handler"
Message:
Maximum call stack size exceeded
Stack:
RangeError: Maximum call stack size exceeded
    at C:\Users\localuser\AppData\Roaming\npm\node_modules\@zowe\cli\node_modules\prettyjson\lib\prettyjson.js:167:19
    at Array.forEach (<anonymous>)
    at renderToArray (C:\Users\localuser\AppData\Roaming\npm\node_modules\@zowe\cli\node_modules\prettyjson\lib\prettyjson.js:145:36)
    at Object.render (C:\Users\localuser\AppData\Roaming\npm\node_modules\@zowe\cli\node_modules\prettyjson\lib\prettyjson.js:210:10)
    at Function.prettyJson (C:\Users\localuser\AppData\Roaming\npm\node_modules\@zowe\cli\node_modules\@zowe\imperative\lib\utilities\src\TextUtils.js:120:27)
    at AmsFileHandler.<anonymous> (C:\Users\localuser\AppData\Roaming\npm\node_modules\@zowe\cli\lib\zosfiles\invoke\amsFile\AmsFile.handler.js:34:75)
    at Generator.next (<anonymous>)
    at fulfilled (C:\Users\localuser\AppData\Roaming\npm\node_modules\@zowe\cli\lib\zosfiles\invoke\amsFile\AmsFile.handler.js:15:58)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

pjfarleyiii avatar Jan 31 '22 01:01 pjfarleyiii

The prettyjson package that Zowe CLI uses to render its output appears to handle large JSON objects poorly: https://github.com/rafeca/prettyjson/issues/43

As the linked issue has been dormant for nearly 3 years, we may need to look for an alternative dependency.

t1m0thyj avatar Jan 31 '22 15:01 t1m0thyj

I finally got around to doing a little more research on this. I'm not qualified to revise the renderToArray function in prettyjson (I do not have a good grasp of Javascript yet) but I found a potential replacement function:

https://github.com/Phrogz/NeatJSON

Seems to not be recursive, which might solve this issue. NeatJSON may be more focused on a browser environment though (it is difficult for me to tell due to my ignorance about Javascript), but I thought I would at least point it out in case it helps.

pjfarleyiii avatar Nov 13 '22 22:11 pjfarleyiii