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

check-html-links returns exit code 0 even when broken links are found #166

Open
d3mondev opened this issue Jun 24, 2021 · 2 comments
Open

Comments

@d3mondev
Copy link

d3mondev commented Jun 24, 2021

Hello,

Since version 0.2.0, check-html-links is not returning an exit code 1 when broken links are found. This is working properly in 0.1.2.

Repro steps assuming _site has broken links:

$ npx check-html-links _site >/dev/null 2>&1 ; echo $?
0
$ npx [email protected] _site >/dev/null 2>&1 ; echo $?
1

Thanks

@d3mondev d3mondev changed the title check-html-links returning exit code 0 even when broken links are found check-html-links returns exit code 0 even when broken links are found Jun 25, 2021
@fidian
Copy link

fidian commented Mar 8, 2025

The issue is in src/CheckHtmlLinksCli.js on line 116. When not specifying the option, this.options.continueOnError is undefined.

if (this.options.continueOnError === false) {

There are two easy fixes. Loosen the comparison ...

if (this.options.continueOnError) {

... or maybe set a default when processing the arguments (line 21).

@fidian
Copy link

fidian commented Mar 8, 2025

If you are hoping to use this in a script, I've found that you can leverage grep to get the right

check-html-links dist/ 2>&1 > /dev/null| ( ! grep --context=1000 '❌' )

For explanation:

  • 2>&1 redirects stderr (the actual problems) to stdout. check-html-links writes all problems to stderr and we need stderr piped into grep to search for the ❌.
  • > /dev/null redirects the original stdin to /dev/null, eliminating it. Otherwise, due to buffering, the stats and progress information is interleaved with the error message. You can skip this if you want the extra output.
  • grep --context=1000 '❌' searches for the ❌ character and writes the surrounding 1000 lines of output. A bit overkill since there won't usually be that many, but not really a problem.
  • ( ! ...) will run the grep command in a subshell and negate the result, which means the successful location of ❌ will turn into an error code from the command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants