feat(core): Added new method getEnvVarOnDemandStrict to throw error for unset env vars

This commit is contained in:
2024-11-22 18:47:50 +01:00
parent 5b1e3a184b
commit e25406662f
5 changed files with 7757 additions and 3940 deletions

View File

@@ -111,6 +111,21 @@ export class Qenv {
}
}
/**
* Like getEnvVarOnDemand, but throws an error if the env var is not set.
* @param envVarNameOrNames
* @returns
*/
public async getEnvVarOnDemandStrict(
envVarNameOrNames: TEnvVarRef | TEnvVarRef[]
): Promise<string> {
const value = await this.getEnvVarOnDemand(envVarNameOrNames);
if (!value) {
throw new Error(`Env var ${envVarNameOrNames} is not set!`);
}
return value;
}
public getEnvVarOnDemandSync(envVarNameOrNames: string | string[]): string | undefined {
console.warn('requesting env var sync leaves out potentially important async env sources.');