Show parse errors in the UI as well

This commit is contained in:
RMidhunSuresh 2022-08-15 17:23:27 +05:30
parent 27363b3f63
commit 2e12ce74b7

View file

@ -35,6 +35,7 @@ export class ThemeLoader {
await this._platform.logger.wrapOrRun(log, "ThemeLoader.init", async (log) => { await this._platform.logger.wrapOrRun(log, "ThemeLoader.init", async (log) => {
let noManifestsAvailable = true; let noManifestsAvailable = true;
const failedManifestLoads: string[] = []; const failedManifestLoads: string[] = [];
const parseErrors: string[] = [];
const results = await Promise.allSettled( const results = await Promise.allSettled(
manifestLocations.map(location => this._platform.request(location, { method: "GET", format: "json", cache: true, }).response()) manifestLocations.map(location => this._platform.request(location, { method: "GET", format: "json", cache: true, }).response())
); );
@ -68,15 +69,19 @@ export class ThemeLoader {
} }
catch(e) { catch(e) {
console.error(e); console.error(e);
parseErrors.push(e.message);
} }
} }
await Promise.all(runtimeThemePromises);
this._themeMapping = { ...builtThemeParser.themeMapping, ...runtimeThemeParser.themeMapping };
if (noManifestsAvailable) { if (noManifestsAvailable) {
// We need at least one working theme manifest! // We need at least one working theme manifest!
throw new Error(`All configured theme manifests failed to load, the following were tried: ${failedManifestLoads.join(", ")}`); throw new Error(`All configured theme manifests failed to load, the following were tried: ${failedManifestLoads.join(", ")}`);
} }
await Promise.all(runtimeThemePromises); else if (Object.keys(this._themeMapping).length === 0 && parseErrors.length) {
this._themeMapping = { ...builtThemeParser.themeMapping, ...runtimeThemeParser.themeMapping }; // Something is wrong..., themeMapping is empty!
Object.assign(this._themeMapping, builtThemeParser.themeMapping, runtimeThemeParser.themeMapping); throw new Error(`Failed to parse theme manifests, the following errors were encountered: ${parseErrors.join(", ")}`);
}
this._addDefaultThemeToMapping(log); this._addDefaultThemeToMapping(log);
log.log({ l: "Preferred colorscheme", scheme: this.preferredColorScheme === ColorSchemePreference.Dark ? "dark" : "light" }); log.log({ l: "Preferred colorscheme", scheme: this.preferredColorScheme === ColorSchemePreference.Dark ? "dark" : "light" });
log.log({ l: "Result", themeMapping: this._themeMapping }); log.log({ l: "Result", themeMapping: this._themeMapping });