cli icon indicating copy to clipboard operation
cli copied to clipboard

JS Packages plugin parsing error when warning is printed

Open matejchalk opened this issue 6 months ago • 0 comments

What happened?

My PNPM repository uses an .npmrc file for publishing, and for many PNPM commands there is a warning printed regarding a missing environment variable. Although the log doesn't doesn't really affect anything (pnpm audit and pnpm outdated work as usual), it causes a parsing error in the Code PushUp plugin, which expects pure JSON in stdout.

What would you expect to happen?

I would expect that additional unrelated logs don't break the Code PushUp plugin. Since those logs have quite a well-defined format, perhaps we could add some logic to filter out those lines before calling JSON.parse?

What steps did you take?

Described above.

Code PushUp package version

0.48.0

What operation system are you on?

Linux

Node version

20.16.0

Relevant log output

Code PushUp CLI
[ info ] Run autorun...
[ warn ] Plugins failed: 
[ warn ] Error: - Plugin JS Packages (js-packages) produced the following error:
  - undefined:1
 WARN  Issue while reading "/home/runner/work/radar-kit-fu/radar-kit-fu/packages/radar/.npmrc". Failed to replace env in config: ${NODE_AUTH_TOKEN}
^

SyntaxError: Unexpected token ' ', " WARN  Iss"... is not valid JSON
    at JSON.parse (<anonymous>)
    at Object.pnpmToOutdatedResult [as unifyResult] (file:///home/runner/work/radar-kit-fu/radar-kit-fu/node_modules/.pnpm/@[email protected]/node_modules/@code-pushup/js-packages-plugin/bin.js:1509:29)
    at processOutdated (file:///home/runner/work/radar-kit-fu/radar-kit-fu/node_modules/.pnpm/@[email protected]/node_modules/@code-pushup/js-packages-plugin/bin.js:1971:40)
    at async executeRunner (file:///home/runner/work/radar-kit-fu/radar-kit-fu/node_modules/.pnpm/@[email protected]/node_modules/@code-pushup/js-packages-plugin/bin.js:1952:57)
    at async file:///home/runner/work/radar-kit-fu/radar-kit-fu/node_modules/.pnpm/@[email protected]/node_modules/@code-pushup/js-packages-plugin/bin.js:2026:1

Node.js v20.16.0

matejchalk avatar Aug 08 '24 14:08 matejchalk