-
Notifications
You must be signed in to change notification settings - Fork 81
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
Standardize and improve exit code handling #245
Standardize and improve exit code handling #245
Conversation
This PR does two things: 1. standardize on: * `exit(1)` when markdownlint runs successfully but finds issues in the input and * `exit(2)` when markdownlint fails to run successfully, perhaps because a configuration file is malformed or perhaps because some kind of filesystem error has occurred 2. handle errors more robustly: a runtime error inside `lintAndPrint()` today results in `exit(1)`, e.g. for a file that we don't have read permissions on (note: this is not comprehensive, we do still do some code execution before `lintAndPrint()`, but this is still a solid improvement)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution!
It feels like this changes the meaning of exit code 2 from what is documented: https://github.com/igorshubovych/markdownlint-cli#exit-codes
Perhaps you want to create a new error code to distinguish these cases from code 1?
FYI, there seem to be issues breaking CI.
Unrelated, you may want to look at the following as it seems similar to your project: https://github.com/github/super-linter
Ah, I somehow looked for this everywhere except in the README! A new error code certainly makes sense. I am slightly concerned about
Ack, opened this and then went to look at something else and didn't see the CI failures. Will keep an eye on these.
Thanks for the heads-up. I should clarify that this isn't just a personal project but we're actually a company and this is one of the products that we're building out, so this is something we're very aware of :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments/questions on the changes.
@@ -24,6 +24,13 @@ function jsYamlSafeLoad(text) { | |||
return require('js-yaml').load(text); | |||
} | |||
|
|||
const exitCodes = { | |||
lintFindings: 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"lintFailures", maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"lintFailures" suggests to me that linting failed to happen, aka an unexpected failure, hence "lintFindings"
This one's a tricky terminology issue and is also frustratingly non standard across a lot of linters :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lintIssues?
test/test.js
Outdated
@@ -126,6 +126,22 @@ test('linting of incorrect Markdown file fails with absolute path', async t => { | |||
} | |||
}); | |||
|
|||
test('linting of unreadable Markdown file fails', async t => { | |||
const unreadablePath = '/tmp/unreadable.md'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you do relative to __dirname? I don't want to reach out like this as some systems may treat that as malware, etc..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, it breaks on Windows. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eurghhh. This was causing race issues with the other tests, that's why I went with /tmp
originally. Need to figure out somewhere it doesn't break the glob tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can give it a non-standard extension? .mdtest or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple more questions, replies to a couple of comments.
markdownlint.js
Outdated
getStdin().then(lintAndPrint); | ||
} else { | ||
program.help(); | ||
function main() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about just putting this inside the try?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
test/test.js
Outdated
try { | ||
fs.writeFileSync(unreadablePath, '', {mode: 0o222}); | ||
|
||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we need the nested try? I think the outer can have a catch and a finally?
Looks like 2 CI issues:
|
|
maybe a deliberately broken symlink will work on windows? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
and thanks to you for being so quick and responsive! |
This PR does two things:
standardize on:
exit(1)
when markdownlint runs successfully but finds issues in the input andexit(2)
when markdownlint fails to run successfully, perhaps because a configuration file is malformed or perhaps because some kind of filesystem error has occurredhandle errors more robustly: a runtime error inside
lintAndPrint()
today results inexit(1)
, e.g. for a file that we don't have read permissions on (note: this is not comprehensive, we do still do some code execution beforelintAndPrint()
, but this is still a solid improvement)The background for this PR is that I'm working on a universal linter which makes it easy for users to run linters for different subsets of their repos, and
markdownlint-cli
usesexit(1)
as a catch-all for not just lint findings but also unexpected failures.Specifically we've seen
markdownlint
return withexit(1)
when this happens:and this can be easily reproduced via: