Skip to content

Commit

Permalink
core(response-compresson): throw on unexpected error
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Jul 12, 2023
1 parent b63e44f commit 59c115b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
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 FRGatherer 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 FRGatherer {
});
});
}).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;
}

Check warning on line 127 in core/gather/gatherers/dobetterweb/response-compression.js

View check run for this annotation

Codecov / codecov/patch

core/gather/gatherers/dobetterweb/response-compression.js#L125-L127

Added lines #L125 - L127 were not covered by tests

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,8 +145,9 @@ 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 () => {
mocks.networkMock.fetchResponseBodyFromCache.mockRejectedValue(
new Error('No resource with given identifier found'));
const artifact = await gatherer._getArtifact(context, networkRecords);
expect(artifact).toHaveLength(2);
expect(artifact[0].resourceSize).toEqual(6);
Expand Down

0 comments on commit 59c115b

Please sign in to comment.