Ugly error on invalid JSON syntax
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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