Skip to content

Commit

Permalink
fix: null checking on client root
Browse files Browse the repository at this point in the history
  • Loading branch information
lshadler committed Aug 26, 2021
1 parent 21621c7 commit fed04a3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/commands/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ export default class InstallCommand extends UpdateCommand {
this.channel = 'stable';
}

const versions = fs
.readdirSync(this.clientRoot)
.filter((dirOrFile) => dirOrFile !== 'bin' && dirOrFile !== 'current');
let versions: string[] = [];
try {
versions = fs
.readdirSync(this.clientRoot)
.filter((dirOrFile) => dirOrFile !== 'bin' && dirOrFile !== 'current');
} catch {}

if (versions.includes(targetVersion)) {
this.log(
Expand Down
12 changes: 9 additions & 3 deletions src/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,15 @@ export default class UpdateCommand extends Command {
);

// Do not show known non-local version folder names, bin and current.
const versions = fs
.readdirSync(this.clientRoot)
.filter((dirOrFile) => dirOrFile !== 'bin' && dirOrFile !== 'current');
let versions: string[] = [];
try {
versions = fs
.readdirSync(this.clientRoot)
.filter(
(dirOrFile) => dirOrFile !== 'bin' && dirOrFile !== 'current',
);
} catch {}

if (versions.length === 0)
throw new Error('No locally installed versions found.');

Expand Down
9 changes: 6 additions & 3 deletions src/commands/use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ export default class UseCommand extends UpdateCommand {
this.debug(`Looking for locally installed versions at ${this.clientRoot}`);

// Do not show known non-local version folder names, bin and current.
const versions = fs
.readdirSync(this.clientRoot)
.filter((dirOrFile) => dirOrFile !== 'bin' && dirOrFile !== 'current');
let versions: string[] = [];
try {
versions = fs
.readdirSync(this.clientRoot)
.filter((dirOrFile) => dirOrFile !== 'bin' && dirOrFile !== 'current');
} catch {}

// Back out if no local versions are found
if (versions.length === 0)
Expand Down

0 comments on commit fed04a3

Please sign in to comment.