From 7becc864b2a95abe47f12d327a09f456ba6f7e88 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Fri, 23 Jun 2023 12:15:37 -0400 Subject: [PATCH] fix: throw good error for bad json config files --- src/config/configFile.ts | 10 ++++++---- src/stateAggregator/accessors/orgAccessor.ts | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/config/configFile.ts b/src/config/configFile.ts index 52d588a7fb..8dfbcba8f0 100644 --- a/src/config/configFile.ts +++ b/src/config/configFile.ts @@ -161,22 +161,24 @@ export class ConfigFile< // internally and updated persistently via write(). if (!this.hasRead || force) { this.logger.info(`Reading config file: ${this.getPath()}`); - const obj = parseJsonMap(await fs.promises.readFile(this.getPath(), 'utf8')); + const obj = parseJsonMap(await fs.promises.readFile(this.getPath(), 'utf8'), this.getPath()); this.setContentsFromObject(obj); } + // Necessarily set this even when an error happens to avoid infinite re-reading. + // To attempt another read, pass `force=true`. + this.hasRead = true; return this.getContents(); } catch (err) { + this.hasRead = true; if ((err as SfError).code === 'ENOENT') { if (!throwOnNotFound) { this.setContents(); return this.getContents(); } } - throw err; - } finally { // Necessarily set this even when an error happens to avoid infinite re-reading. // To attempt another read, pass `force=true`. - this.hasRead = true; + throw err; } } diff --git a/src/stateAggregator/accessors/orgAccessor.ts b/src/stateAggregator/accessors/orgAccessor.ts index 603577b4a4..263ef157e1 100644 --- a/src/stateAggregator/accessors/orgAccessor.ts +++ b/src/stateAggregator/accessors/orgAccessor.ts @@ -42,6 +42,9 @@ export abstract class BaseOrgAccessor