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

Feature request: Support full error messages in getUrlsFromSitemap #186

Open
ashleemboyer opened this issue May 30, 2022 · 0 comments
Open

Comments

@ashleemboyer
Copy link

Background

Hello! 👋🏻 First of all, thanks for such a helpful tool. I love running pa11y-ci as a GitHub pull request workflow against a newly-built sitemap on Next.js sites. It helps me catch a lot of the easy stuff and also prevent regressions! 🙌🏻

This brings me to an issue I ran into today. I was trying to add a GitHub workflow I commonly use to a Next.js site, but kept getting the following error:

The sitemap "<url>" could not be parsed

It took a lot of manual debugging for me to figure out what the core issue was. I tried using other CLI options, comparing configuration with other projects I've successfully added my workflow to, and finally tried copy-pasting some of the source code to test locally on my machine. After adding many console.logs to first understand the code and then second to isolate where the error was, I found this node-fetch error was the source of my troubles:

TypeError: Only absolute URLs are supported

After that, I Googled the error message under node-fetch, took another look at my generated sitemap files, and found that the URLs generated did not start with https://. After I added those back in, my workflow was successful! 🎉

Request

Although my quest was successful, it did take somewhere around one hour to debug the problem. I'm confident it would have taken me less than 15 minutes to debug if the TypeError: Only absolute URLs are supported had been visible from the beginning. My proposal is to update the error handling in getUrlsFromSitemap to no longer lose the errors it catches.

These are the lines in particular: https://github.com/pa11y/pa11y-ci/blob/master/bin/pa11y-ci.js#L253-L258

function getUrlsFromSitemap(sitemapUrl, config) {
  return Promise.resolve()
    .then(() => fetch(sitemapUrl))
    .then((response) => response.text())
    .then((body) => {
      // cheerio code ...
    })
    .catch((error) => {
      if (error.stack && error.stack.includes('node-fetch')) {
        throw new Error(`The sitemap "${sitemapUrl}" could not be loaded`);
      }
      throw new Error(`The sitemap "${sitemapUrl}" could not be parsed`);
    });
}

Thank you for the consideration! 💖

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

No branches or pull requests

2 participants