Skip to content

Surface runtime errors in Deploy Log and Deploy Summary #505

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

Merged
merged 6 commits into from
Oct 27, 2022

Conversation

jackbrewer
Copy link
Contributor

@jackbrewer jackbrewer commented Oct 26, 2022

Closes https://github.com/netlify/netlify-plugin-lighthouse/issues/503
Closes https://github.com/netlify/netlify-plugin-lighthouse/issues/494
Closes https://github.com/netlify/netlify-plugin-lighthouse/issues/415

Likely solves others with mention of undefined results. We should do an issue sweep on Thurs

Ensures any runtime errors reported by Lighthouse are passes around alongside the rest of the data. This is then surfaced in the Deploy Log (directly after the failing run) and as an item in the Deploy summary.

This PR also moves some "data formatting" functions to a standalone file and adds tests. In my first attempt, these were being more heavily modified to deal with the runtimeError, but I ended up undoing that. It seemed a shame to put the functions back, so I've kept them. I've marked the exact sections which changes for easier reviewing.

For Netlifiers, check out https://app.netlify.com/sites/with-lighthouse-plugin/deploys/6359368d902825000811cdfa#L695

Deploy Summary
Three runs, one of which failed:
image

We use the error string provided by Lighthouse. I considered writing a few shorter versions to go in the Deploy Summary but seeing the list of possible variations made me think again!

Deploy Log
image

We're showing the full error here, not just the message part. This should help add some google-ability using the code incase the message text changes in future.

return actual < expected;
};

const getError = (id, expected, categories, audits) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unchanged, just moved and tested

const { minify } = require('html-minifier');
const { makeReplacements } = require('./replacements');

const belowThreshold = (id, expected, categories) => {
Copy link
Contributor Author

@jackbrewer jackbrewer Oct 26, 2022

Choose a reason for hiding this comment

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

Function unchanged, just moved and tested

return { message: categoryError, details: categoryAudits };
};

const formatShortSummary = (categories) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Split out from following function

};

const formatResults = ({ results, thresholds }) => {
const runtimeError = results.lhr.runtimeError;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New line

...(thresholds[id] ? { threshold: thresholds[id] } : {}),
}));

const shortSummary = formatShortSummary(categories);
Copy link
Contributor Author

@jackbrewer jackbrewer Oct 26, 2022

Choose a reason for hiding this comment

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

Now uses formatShortSummary (previous function in file) as a standalone function rather than doing in-place

minifyJS: true,
});

return { summary, shortSummary, details, report, errors, runtimeError };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adds runtimeError to the end

}, {});
}

if (runtimeError) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Send the runtimeError off to the Deploy Summary, instead of shortSumary (which is undefined)

@@ -289,17 +240,23 @@ module.exports = {
output_path,
settings,
});
if (summary) {

if (summary && !runtimeError) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't show the summary when there's an error


const fullPath = [serveDir, path].join('/');
if (report) {
const size = Buffer.byteLength(JSON.stringify(report));
console.log(
`Report collected: audited_uri: '${chalk.magenta(
url || fullPath,
)}', html_report_size: ${chalk.magenta(size / 1024)} KiB`,
)}', html_report_size: ${chalk.magenta(
+(size / 1024).toFixed(2),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Random bonus fix to round the file size to maximum 2 decimal places

@@ -54,9 +54,6 @@ const runLighthouse = async (browserPath, url, settings) => {
},
settings,
);
if (results.lhr.runtimeError) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needed to be removed to allow the error to be handle more gracefully elsewhere

@jackbrewer jackbrewer requested a review from aitchiss October 26, 2022 13:59
@jackbrewer jackbrewer self-assigned this Oct 26, 2022
return actual < expected;
};

const getError = (id, expected, categories, audits) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function unchanged, just moved and tested

aitchiss
aitchiss previously approved these changes Oct 27, 2022
Copy link
Contributor

@aitchiss aitchiss left a comment

Choose a reason for hiding this comment

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

Nice! This is going to make things much clearer ✨

const persistResults = async ({ report, path }) => {
await fs.mkdir(dirname(path), { recursive: true });
await fs.writeFile(path, report);
};

const getUtils = ({ utils }) => {
// This function checks to see if we're running within the Netlify Build system,
Copy link
Contributor

Choose a reason for hiding this comment

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

Love the additional comments 😍

@jackbrewer jackbrewer marked this pull request as ready for review October 27, 2022 14:06
@jackbrewer jackbrewer requested a review from a team October 27, 2022 14:06
@netlify
Copy link

netlify bot commented Oct 27, 2022

👷 Deploy Preview for plugin-lighthouse processing.

Name Link
🔨 Latest commit f190323
🔍 Latest deploy log https://app.netlify.com/sites/plugin-lighthouse/deploys/635a9ec3cab6a400096d0783

@jackbrewer
Copy link
Contributor Author

CI is failing on the coloured strings. I'll try some simpler partial text matching instead

@jackbrewer
Copy link
Contributor Author

Managed to get there eventually… tests are passing on CI now that ANSI codes are stripped

@jackbrewer jackbrewer requested a review from aitchiss October 27, 2022 15:15
@jackbrewer jackbrewer merged commit 77ccef3 into main Oct 27, 2022
@jackbrewer jackbrewer deleted the jbr/surfaceErrorInSummary branch October 27, 2022 15:26
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

Successfully merging this pull request may close these issues.

surface runtime errors Surface error message if requested path/url 404s Customer issue: Results not reported after plugin seems to run successfully
2 participants