as a developer, I'd like to catch lighthouse errors in audits, gatherers, runtime etc outside of lighthouse
Wrapping lighthouse in a try()/catch() wont catch all errors. It seems like when errors are encountered in lighthouse audits, the thrown error's message (LighthouseError class) is stored as the errorMessage attribute of the audit result. If a gatherer hits a Lighthouse Error then I'm not even sure where you can access these?
We are hitting PAGE_HUNG, ERRORED_DOCUMENT errors and so on and would like to capture these events so as to do something meaningful within our application. Doing it like this is a bit unsavoury...
Object.values(audits).forEach(audit => {
if (audit.errorMessage) {
erroredAudits.push(audit);
}
});
...
I'd like to capture errors thrown anywhere within the program; audits, gatherers, runtime etc and handle them ourselves. Something like binding a custom exception listener to the lighthouse() instance in Node. Our use case is catching errors to do with page loading (PAGE_HUNG, DNS_FAILURE) and so on, so we can report "your page is really bad, we can't even audit it" to users, rather than not being able to deliver any audit information to the user at all.
Any suggestions?
Howdy chief! Appreciate you filing this bug. :clap: This error means that the page stopped responding. The solution here is to re-run. If the error repeats, the page or your machine creates infinite loops and needs to be fixed. :robot: Beep beep boop.
Howdy chief! Appreciate you filing this bug. :clap: This error means that the page stopped responding. The solution here is to re-run. If the error repeats, the page or your machine creates infinite loops and needs to be fixed. :robot: Beep beep boop.
Something like binding a custom exception listener
That's an interesting idea.
In the meantime ... We have one client (Lightrider / PSI) that sort of catches errors (but just fatal ones) and returns a mega-partial LHR (just {runtimeError}). See https://github.com/GoogleChrome/lighthouse/blob/master/clients/lightrider/lightrider-entry.js#L68. It doesn't catch errors like DNS_ERROR (i think that can happen in a single pass) but it should catch PAGE_HUNG (a fatal error). If you want to snoop on all the audit errors, you'd have to do like in your provided code sample, but you could shorten it to:
const erroredAudits .= audits.filter(a => a.errorMessage)
const errors = erroredAudits.map(a => a.errorMessage)
or w/e.
@paulirish this bot won't leave this issue alone.
Hey, thanks for the reply.
Yeah, so we are wanting do so something like what you are doing with lightrider, but for "page/network" errors (these are non-fatal, right?) in addition to catching fatal/runtime errors.
Our current approach is, for a specific set of 'lhPageErrors' (see below), catch them. Do this by wrapping TimeToInteractiveAudit in a custom audit with an error catch/throw that bubbles up to the scope we need it at. TTI audit was chosen as it seems to throw the majority of the "lighthouse is gonna fall over" errors.
When encountered, close browser, open another and run lh again with a special "lite" config that returns a LHR with just 1 result, a custom audit "Very high document interactive time", rawValue = false. We figured/observed that the presence of any of these errors means that the rest of the lighthouse is unlikely to run very well, so we just fail fast and safely, but deliver some result to the user.
const lhPageErrors = [
'PAGE_SPECIFIC_ISSUE',
'NO_TTI_CPU_IDLE_PERIOD',
'NO_TTI_NETWORK_IDLE_PERIOD',
'NO_DOCUMENT_REQUEST',
'FAILED_DOCUMENT_REQUEST',
'ERRORED_DOCUMENT_REQUEST',
'INSECURE_DOCUMENT_REQUEST',
'PAGE_HUNG',
'DNS_FAILURE',
];
re: snooping erroredAudits, OK thanks for the tip- would this work? the error message is sometimes equal to the error code (which would work), but if the audit failed because the gatherer failed, you get a message like:
xxx gatherer, required by audit yyy, encountered an error: ERROR_CODE
which is a little bit annoying to detect reliably. I guess you could do a message.inlcudes(errorCodes) but its getting a bit hacky for my liking.
Does the presence of an errorMessage in the audit result mean that the result cannot be trusted and therefore we shouldn't include in our report?
Does the presence of an errorMessage in the audit result mean that the result cannot be trusted and therefore we shouldn't include in our report?
it means there's an error and this audit doesn't have valid data. we personally show these errors to the user as sometimes they are actionable.
which is a little bit annoying to detect reliably. I guess you could do a
message.inlcudes(errorCodes)but its getting a bit hacky for my liking.
agree this sucks. A few things we could do to improve these sorts of usecases
- We could add a
error: { code, message }object to an audit's results in these cases. - we could expose something like a
lighthouseerrorevent in JS so you can define a custom listener - other stuff.
Since this was a while ago, I feel like it's not an urgent need. I'll close this issue, but can reopen it if there's still interest from folks.