-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
clients(lightrider): serialize errors in artifacts #9410
Changes from 10 commits
be5c3cb
e1968bd
977f8a1
3ce20d2
12e460f
73c79c2
0cf7402
e932e33
181cc8e
e23131c
c7aebaa
0836365
6e03048
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ const lighthouse = require('../../lighthouse-core/index.js'); | |
|
||
const LHError = require('../../lighthouse-core/lib/lh-error.js'); | ||
const preprocessor = require('../../lighthouse-core/lib/proto-preprocessor.js'); | ||
const assetSaver = require('../../lighthouse-core/lib/asset-saver.js'); | ||
|
||
/** @type {Record<'mobile'|'desktop', LH.Config.Json>} */ | ||
const LR_PRESETS = { | ||
|
@@ -54,15 +55,23 @@ async function runLighthouseInLR(connection, url, flags, lrOpts) { | |
const runnerResult = await lighthouse(url, flags, config, connection); | ||
if (!runnerResult) throw new Error('Lighthouse finished without a runnerResult'); | ||
|
||
// When LR is called with |internal: {keep_raw_response: true, save_lighthouse_assets: true}|, | ||
// this code will log artifacts to raw_response.artifacts. | ||
// pre process the LHR for proto | ||
const preprocessedLhr = preprocessor.processForProto(runnerResult.lhr); | ||
|
||
if (logAssets) { | ||
// @ts-ignore - piggyback the artifacts on the LHR. | ||
runnerResult.lhr.artifacts = runnerResult.artifacts; | ||
} | ||
// When LR is called with |internal: {keep_raw_response: true, save_lighthouse_assets: true}|, | ||
// this code will log artifacts to raw_response.artifacts. | ||
|
||
// pre process the LHR for proto | ||
return JSON.stringify(preprocessor.processForProto(runnerResult.lhr)); | ||
// Properly serialize artifact errors. | ||
const artifactsJson = JSON.stringify(runnerResult.artifacts, assetSaver.stringifyReplacer); | ||
|
||
return JSON.stringify({ | ||
...preprocessedLhr, | ||
artifacts: JSON.parse(artifactsJson), | ||
}); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't decide if the else is necessary or not. I'm flip flopping on keeping it in/removing it is more readable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'd fall on the side of no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you be more specific about what you are suggesting instead There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're returning in both sides of the if/else. You can just remove the else here to always return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you see what i'm doing with artifacts tho. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh i see now |
||
return JSON.stringify(preprocessedLhr); | ||
} | ||
} catch (err) { | ||
// If an error ruined the entire lighthouse run, attempt to return a meaningful error. | ||
let runtimeError; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,4 +288,5 @@ module.exports = { | |
prepareAssets, | ||
saveTrace, | ||
saveLanternNetworkData, | ||
stringifyReplacer, | ||
}; |
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.
Move comment to be above
if (logAssets) {