Skip to content

Commit

Permalink
fix: more descriptive error names
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed May 20, 2021
1 parent 4954e1c commit 292d9f5
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/service/registry/cache-registry/cache-registry-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {ILoggerService} from "../../logger/i-logger-service";
import {PolyfillDictEntry, PolyfillDictNormalizedEntry} from "../../../polyfill/polyfill-dict";
import pkg from "../../../../package.json";
import {Config} from "../../../config/config";
import {ApiError} from "../../../api/lib/api-error";
import {StatusCodes} from "http-status-codes";

/**
* A class that can cache generated Polyfills on disk
Expand Down Expand Up @@ -67,9 +69,15 @@ export class CacheRegistryService implements ICacheRegistryService {
const buffer = await this.getFromCache(this.getCachePathForPolyfillSet(input, context));
// If not possible, return undefined
if (buffer == null) return undefined;
let polyfillFeatures: PolyfillFeature[];

// Otherwise, store it in the memory registry and return the Buffer
return await this.memoryRegistry.setPolyfillFeatureSet(input, new Set(JSON.parse(buffer.toString())), context);
try {
polyfillFeatures = JSON.parse(buffer.toString());
} catch (ex) {
throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, `Could not decode polyfill features based on the buffer: ${buffer.toString()}`);
}
return await this.memoryRegistry.setPolyfillFeatureSet(input, new Set(polyfillFeatures), context);
}

/**
Expand Down Expand Up @@ -229,7 +237,11 @@ export class CacheRegistryService implements ICacheRegistryService {
*/
private async getPackageVersionMap(): Promise<{[key: string]: string}> {
const packageVersionMapRaw = await this.getFromCache(constant.path.cachePackageVersionMap);
return packageVersionMapRaw == null ? {} : JSON.parse(packageVersionMapRaw.toString());
try {
return packageVersionMapRaw == null ? {} : JSON.parse(packageVersionMapRaw.toString());
} catch (ex) {
throw new ApiError(StatusCodes.INTERNAL_SERVER_ERROR, "Could not decode package version Map");
}
}

private async getLastCachedPolyfillConfigChecksum(): Promise<string | undefined> {
Expand Down

0 comments on commit 292d9f5

Please sign in to comment.