Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 1965461

Browse files
committed
fix: improve error handling
1 parent 138b5bc commit 1965461

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/Environment.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,11 @@ export default class Environment {
172172
const envs = []
173173
for (let name of names) {
174174
const env = new Environment(name)
175+
const built = await env.built()
175176
envs.push(Object.assign({}, env, {
176177
path: env.path(),
177-
built: await env.built(),
178-
location: await nix.location(name)
178+
built: built,
179+
location: built ? await nix.location(name) : '-'
179180
}))
180181
}
181182
return envs
@@ -456,10 +457,17 @@ export default class Environment {
456457
// During development you'll need to use ---pure=false so that
457458
// node is available to run Nixster. In production, when a user
458459
// has installed a binary, this shouldn't be necessary
459-
let nixsterPath = await spawn('which', ['nixster'])
460-
const tempRcFile = tmp.fileSync()
461-
fs.writeFileSync(tempRcFile.name, `alias nixster="${nixsterPath.toString().trim()}"\n`)
462-
shellArgs.push('--rcfile', tempRcFile.name)
460+
let nixsterPath
461+
try {
462+
nixsterPath = await spawn('which', ['nixster'])
463+
} catch (error) {
464+
// Nixster not on path
465+
}
466+
if (nixsterPath) {
467+
const tempRcFile = tmp.fileSync()
468+
fs.writeFileSync(tempRcFile.name, `alias nixster="${nixsterPath.toString().trim()}"\n`)
469+
shellArgs.push('--rcfile', tempRcFile.name)
470+
}
463471
}
464472

465473
// Environment variables

src/nix.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export async function location (env: string): Promise<string> {
250250
const profile = path.join(profiles, env)
251251
if (!fs.existsSync(profile)) throw new Error(`Profile for environment "${env}" not exist at "${profile}"`)
252252
const location = await spawn('readlink', ['-f', profile])
253-
if (location.length === 0) throw new Error(`Could not resolve location of environment "${env}" from the profile "${profile}"`)
253+
if (location.trim().length === 0) throw new Error(`Could not resolve location of environment "${env}" from the profile "${profile}"`)
254254
return location
255255
}
256256

0 commit comments

Comments
 (0)