diff options
Diffstat (limited to 'u/process')
-rw-r--r-- | u/process/env.ts | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/u/process/env.ts b/u/process/env.ts index e80ec4a..c3ae800 100644 --- a/u/process/env.ts +++ b/u/process/env.ts @@ -1,10 +1,12 @@ import { Either, type IEither } from "@emprespresso/utils"; export const getRequiredEnv = (name: string): IEither<Error, string> => - Either.fromFailable(() => { - const value = Deno.env.get(name); // could throw when no permission. - if (!value) { - throw new Error(`environment variable "${name}" is required D:`); - } - return value; - }); + Either + .fromFailable<Error, string | undefined>(() => Deno.env.get(name)) // could throw when no permission. + .flatMap((v) => + (v && + Either.right(v)) || + Either.left( + new Error(`environment variable "${name}" is required D:`), + ) + ); |