Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): log error when config file has syntax error #5057

Merged
merged 2 commits into from
Dec 26, 2019

Conversation

souravdasslg
Copy link
Contributor

@souravdasslg souravdasslg commented Dec 24, 2019

I have implemented this solution by matching if the error is an instance of SyntaxError. Is this how it expected to work?

I am still not able to reach 100% code coverage after many attempts. Some help is much needed.
Issue #4894

@claassistantio
Copy link

claassistantio commented Dec 24, 2019

CLA assistant check
All committers have signed the CLA.

@rarkins
Copy link
Collaborator

rarkins commented Dec 24, 2019

I think it’s ok to skip giving full details and instead just log the full error and say “could not parse config file”. Also ok to skip coverage if you keep it simple.

@souravdasslg souravdasslg changed the title [WIP] fix(config): log error when config file has syntax error fix(config): log error when config file has syntax error Dec 24, 2019
@souravdasslg
Copy link
Contributor Author

Made the changes accordingly :)

@rarkins
Copy link
Collaborator

rarkins commented Dec 24, 2019

What does an example error now look like?

@souravdasslg
Copy link
Contributor Author

This is how the log message is looking like. I feel it is ugly.

$ babel-node --extensions ".ts,.js" -- lib/renovate.ts
FATAL: Could not parse config file
/Volumes/Felix/Work/renovate/config.js:8
"onboardingConfig": {
^^^^^^^^^^^^^^^^^^

   SyntaxError: Unexpected string
       at Module._compile (internal/modules/cjs/loader.js:895:18)
       at Module._compile (/Volumes/Felix/Work/Open Source/renovate/node_modules/pirates/lib/index.js:99:24)
       at Module._extensions..js (internal/modules/cjs/loader.js:995:10)
       at Object.newLoader [as .js] (/Volumes/Felix/Work/Open Source/renovate/node_modules/pirates/lib/index.js:104:7)
       at Module.load (internal/modules/cjs/loader.js:815:32)
       at Function.Module._load (internal/modules/cjs/loader.js:727:14)
       at Module.require (internal/modules/cjs/loader.js:852:19)
       at require (internal/modules/cjs/helpers.js:74:18)
       at Object.getConfig (/Volumes/Felix/Work/Open Source/renovate/lib/config/file.ts:15:14)
       at Object.parseConfigs (/Volumes/Felix/Work/Open Source/renovate/lib/config/index.ts:50:60)
       at processTicksAndRejections (internal/process/task_queues.js:93:5)
       at Object.start (/Volumes/Felix/Work/Open Source/renovate/lib/workers/global/index.ts:68:18)
       at /Volumes/Felix/Work/Open Source/renovate/lib/renovate.ts:9:22

FATAL: You must configure a GitHub personal access token
INFO: Renovate is exiting with a non-zero code due to the following logged errors
"loggerErrors": [
{
"name": "renovate",
"level": 60,
"msg": "Could not parse config file \n /Volumes/Felix/Work/renovate/config.js:8\n "onboardingConfig": {\n ^^^^^^^^^^^^^^^^^^\n\nSyntaxError: Unexpected string\n at Module._compile (internal/modules/cjs/loader.js:895:18)\n at Module._compile (/Volumes/Felix/Work/Open Source/renovate/node_modules/pirates/lib/index.js:99:24)\n at Module._extensions..js (internal/modules/cjs/loader.js:995:10)\n at Object.newLoader [as .js] (/Volumes/Felix/Work/Open Source/renovate/node_modules/pirates/lib/index.js:104:7)\n at Module.load (internal/modules/cjs/loader.js:815:32)\n at Function.Module._load (internal/modules/cjs/loader.js:727:14)\n at Module.require (internal/modules/cjs/loader.js:852:19)\n at require (internal/modules/cjs/helpers.js:74:18)\n at Object.getConfig (/Volumes/Felix/Work/Open Source/renovate/lib/config/file.ts:15:14)\n at Object.parseConfigs (/Volumes/Felix/Work/Open Source/renovate/lib/config/index.ts:50:60)\n at processTicksAndRejections (internal/process/task_queues.js:93:5)\n at Object.start (/Volumes/Felix/Work/Open Source/renovate/lib/workers/global/index.ts:68:18)\n at /Volumes/Felix/Work/Open Source/renovate/lib/renovate.ts:9:22"
},
{
"name": "renovate",
"level": 60,
"msg": "You must configure a GitHub personal access token"
}
]
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@rarkins
Copy link
Collaborator

rarkins commented Dec 24, 2019

I think it’s ok to be ugly if it’s rare and should happen only once.

// istanbul ignore if
if (err instanceof SyntaxError) {
logger.fatal(`Could not parse config file \n ${err.stack}`);
return null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's quit out (abort) instead of continuing. Otherwise a single typo could result in a complete change of config for 10s/100s/1000s of repos.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found out

  1. Even if the config is wrong, with a valid token renovate continues to operate.That doesn't the fix for the problem.

  2. I added the return to prevent the continuation

Do you want me to have process.exit(1) there ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, process.exit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the changes accordingly.Its the best way to solve this error
Also, the error message is more clear now.

@rarkins rarkins merged commit ff07979 into renovatebot:master Dec 26, 2019
@renovate-release
Copy link
Collaborator

🎉 This PR is included in version 19.89.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants