Skip to content

Commit

Permalink
fix: Handle local package database errors better (#8)
Browse files Browse the repository at this point in the history
* Handle local package database errors better

If a 'local' package doesn't exist, we can just not count it.

* Better handling of missing local packages
  • Loading branch information
danopia committed Dec 1, 2021
1 parent ab2e349 commit b438ef0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/metrics/databaseMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ async function* iterateLocalDatabase(
// do the async fetching loop
const packageList = await getPkgList();
for (const packageName of packageList) {
const packageMeta = await getPkgMetadata(packageName);
// handle missing packages: https://github.com/freight-hub/verdaccio-openmetrics/issues/7
const packageMeta = await getPkgMetadata(packageName).catch(err => {
const reason = (err as Error).message || `${err}`;
// eslint-disable-next-line no-console
console.error(`WARN: Failed to fetch local package "${packageName}" for database metrics: ${reason}`);
return null;
});
if (packageMeta) {
yield packageMeta;
}
Expand Down

0 comments on commit b438ef0

Please sign in to comment.