Unitech / Unitech/pm2

Ugly error on invalid JSON syntax

Open
#1,440 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

S: Open for PR T: Bug T: Enhancement
Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

If I forgot a comma in ecosystem.json, pm2 will die with this horrible error:

$ pm2 start /home/dandv/idr/ecosystem.json5

/usr/lib/node_modules/pm2/lib/CLI.js:2300
    return vm.runInNewContext(code, sandbox, filename);
              ^
SyntaxError: Unexpected identifier
    at parseConfig (/usr/lib/node_modules/pm2/lib/CLI.js:2300:15)
    at Object.CLI._startJson (/usr/lib/node_modules/pm2/lib/CLI.js:283:15)
    at Object.CLI.start (/usr/lib/node_modules/pm2/lib/CLI.js:91:9)
    at Command.commander.command.option.option.option.option.option.description.action.line (/usr/lib/node_modules/pm2/bin/pm2:205:11)
    at Command.listener (/usr/lib/node_modules/pm2/node_modules/commander/index.js:301:8)
    at Command.emit (events.js:98:17)
    at Command.parseArgs (/usr/lib/node_modules/pm2/node_modules/commander/index.js:610:12)
    at Command.parse (/usr/lib/node_modules/pm2/node_modules/commander/index.js:458:21)
    at beginCommandProcessing (/usr/lib/node_modules/pm2/bin/pm2:116:13)
    at commander.command.option.option.option.option.option.description.action.line (/usr/lib/node_modules/pm2/bin/pm2:169:7)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with parseConfig in lib/CLI.js, especially the path reached by CLI._startJson when running pm2 start on an invalid ecosystem file. Reproduce the malformed JSON example and inspect how the syntax error is surfaced; done means invalid syntax produces a useful user-facing error rather than the raw stack trace.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.