Commit ca27d16a authored by Philip Paetz's avatar Philip Paetz

feat(DX): improved error message when process.env.NODE_ENV is undefined

parent 9b15700a
......@@ -24,25 +24,35 @@ export = class StrongConfig {
this.runtimeEnv = process.env[this.options.runtimeEnvName]
}
public load(): ReturnType<typeof load> {
private checkRuntimeEnv(): void {
if (R.isNil(this.runtimeEnv)) {
throw new Error('runtimeEnv must be defined.')
throw new Error(
`[💪 strong-config] Can't load config: process.env.${this.options.runtimeEnvName} is undefined.
Maybe you have forgotten to set the environment variable ${this.options.runtimeEnvName} when starting your application?
For example: 'NODE_ENV=production yarn start'\n`
)
}
}
public load(): ReturnType<typeof load> {
this.checkRuntimeEnv()
if (this.config) {
return this.config
}
/* eslint-disable-next-line */
// @ts-ignore because we're checking for 'undefined' in this.checkRuntimeEnv() already
this.config = load(this.runtimeEnv, this.options)
return this.config
}
public validate(): ReturnType<typeof validate> {
if (R.isNil(this.runtimeEnv)) {
throw new Error('runtimeEnv must be defined.')
}
this.checkRuntimeEnv()
/* eslint-disable-next-line */
// @ts-ignore because we're checking for 'undefined' in this.checkRuntimeEnv() already
return validate(this.runtimeEnv, this.options.configRoot)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment