Skip to content

Commit 7028b7f

Browse files
robhoganfacebook-github-bot
authored andcommittedSep 16, 2022
Warn and annotate on metro-file-map cache read error
Summary: Currently `metro-file-map` will *silently* ignore errors encountered when reading from the configured cache manager, and fall back to a cold crawl. This adds a console warning and records an annotation to give these error cases more visibility. In addition, propagate unexpected errors, such as deserialisation failures, from the default `DiskCacheManager`. Changelog: **[Fix]** Log warning on unexpected error during `metro-file-map`cache read. Reviewed By: huntie Differential Revision: D39514918 fbshipit-source-id: 4569a1ed7f2114307c96c0b5064b367ebd487947
1 parent ace28a9 commit 7028b7f

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed
 

‎packages/metro-file-map/src/cache/DiskCacheManager.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,14 @@ export class DiskCacheManager implements CacheManager {
6868
async read(): Promise<?InternalData> {
6969
try {
7070
return deserialize(readFileSync(this._cachePath));
71-
} catch {}
72-
return null;
71+
} catch (e) {
72+
if (e?.code === 'ENOENT') {
73+
// Cache file not found - not considered an error.
74+
return null;
75+
}
76+
// Rethrow anything else.
77+
throw e;
78+
}
7379
}
7480

7581
async write(

‎packages/metro-file-map/src/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,15 @@ export default class HasteMap extends EventEmitter {
411411
this._options.perfLogger?.point('read_start');
412412
try {
413413
data = await this._cacheManager.read();
414-
} catch {}
414+
} catch (e) {
415+
this._console.warn(
416+
'Error while reading cache, falling back to a full crawl:\n',
417+
e,
418+
);
419+
this._options.perfLogger?.annotate({
420+
string: {cacheReadError: e.toString()},
421+
});
422+
}
415423
data = data ?? this._createEmptyMap();
416424
this._options.perfLogger?.point('read_end');
417425

0 commit comments

Comments
 (0)
Please sign in to comment.