Skip to content

Commit

Permalink
fix: Error reporting when config file was not found
Browse files Browse the repository at this point in the history
  • Loading branch information
schw4rzlicht committed Jun 14, 2020
1 parent 9d97959 commit 78fc048
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function init(): void {
}

export function notifyUpdate(manifest: any) {
if(semverGt(manifest.version, packageInformation.version)) {
if (semverGt(manifest.version, packageInformation.version)) {
console.log(chalk`🔔 {blue A new version of ${packageInformation.name} is available!} ` +
chalk`{blue (current: {bold ${packageInformation.version}}, new: {bold ${manifest.version}})}`);
}
Expand Down Expand Up @@ -90,7 +90,17 @@ export async function loadConfig(configFile: string): Promise<Config> {
configFile = "config.json";
}

let rawConfigFile = Fs.readFileSync(configFile, {encoding: "utf-8"});
let rawConfigFile: any = _.attempt(() => Fs.readFileSync(configFile, {encoding: "utf-8"}));

if(rawConfigFile instanceof Error) {
// @ts-ignore
if(rawConfigFile.code === "ENOENT") {
throw new ConfigError(`Could not open config file ${configFile}!`);
} else {
throw rawConfigFile;
}
}

let rawConfigObject = _.attempt(() => JSON.parse(rawConfigFile));

if (rawConfigObject instanceof Error) {
Expand Down

0 comments on commit 78fc048

Please sign in to comment.