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

core(response-compresson): throw on unexpected error #15259

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions core/gather/gatherers/dobetterweb/response-compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
import {Buffer} from 'buffer';
import {gzip} from 'zlib';

import log from 'lighthouse-logger';

import BaseGatherer from '../../base-gatherer.js';
import UrlUtils from '../../../lib/url-utils.js';
import {Sentry} from '../../../lib/sentry.js';
import {NetworkRequest} from '../../../lib/network-request.js';
import DevtoolsLog from '../devtools-log.js';
import {fetchResponseBodyFromCache} from '../../driver/network.js';
Expand Down Expand Up @@ -119,12 +120,13 @@ class ResponseCompression extends BaseGatherer {
});
});
}).catch(err => {
Sentry.captureException(err, {
tags: {gatherer: 'ResponseCompression'},
extra: {url: UrlUtils.elideDataURI(record.url)},
level: 'warning',
});
const isExpectedError = err?.message?.includes('No resource with given identifier found');
if (!isExpectedError) {
err.extra = {url: UrlUtils.elideDataURI(record.url)};
throw err;
}

log.error('ResponseCompression', err.message);
record.gzipSize = undefined;
return record;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,21 @@ describe('Optimized responses', () => {
expect(artifact[0].gzipSize).toEqual(26);
});

it('recovers from driver errors', async () => {
mocks.networkMock.fetchResponseBodyFromCache.mockRejectedValue(new Error('Failed'));
it('recovers from cache ejection errors', async () => {
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
mocks.networkMock.fetchResponseBodyFromCache.mockRejectedValue(
new Error('No resource with given identifier found'));
const artifact = await gatherer.getCompressibleRecords(context, networkRecords);
expect(artifact).toHaveLength(2);
expect(artifact[0].resourceSize).toEqual(6);
expect(artifact[0].gzipSize).toBeUndefined();
});

it('does not suppress other errors', async () => {
mocks.networkMock.fetchResponseBodyFromCache.mockRejectedValue(new Error('Failed'));
await expect(gatherer.getCompressibleRecords(context, networkRecords))
.rejects.toThrow();
});

it('ignores responses from installed Chrome extensions', async () => {
const networkRecords = [
{
Expand Down