@@ -14,22 +14,19 @@ export function getEnvVar(key: string): string | undefined {
14
14
interface GetConfigOptions {
15
15
warn ?: boolean ;
16
16
nullishString ?: boolean ;
17
- throwErrorIfNotFound ?: boolean ;
18
17
}
19
18
20
19
const DEFAULT_GET_CONFIG_OPTIONS : GetConfigOptions = {
21
20
warn : ! isTestEnvironment ,
22
- nullishString : false ,
23
- throwErrorIfNotFound : false
21
+ nullishString : false
24
22
} ;
25
23
26
24
/**
27
25
* Returns a string config value from environment variables.
28
- * Logs a warning or throws an error if the value is missing, if `warn` and `throwErrorIfNotFound` are true in options
26
+ * Logs a warning if the value is missing, if `warn` is true in options
29
27
*
30
28
* @param key - The environment variable key to fetch.
31
29
* @param options - Optional settings:
32
- * - `throwErrorIfNotFound`: whether to throw an error if the value is missing (default to `false`).
33
30
* - `warn`: whether to warn if the value is missing (default `true` unless in test env).
34
31
* - `nullishString`: if true, returns `''` instead of `undefined` when missing.
35
32
* @returns String value of the env var, or `''` or `undefined` if missing.
@@ -43,7 +40,7 @@ export function getConfig(
43
40
}
44
41
45
42
// override default options with param options
46
- const { warn, nullishString, throwErrorIfNotFound } = {
43
+ const { warn, nullishString } = {
47
44
...DEFAULT_GET_CONFIG_OPTIONS ,
48
45
...options
49
46
} ;
@@ -55,10 +52,7 @@ export function getConfig(
55
52
if ( value == null || value === '' ) {
56
53
const notFoundMessage = `getConfig("${ key } ") returned null or undefined` ;
57
54
58
- // error, warn or continue if no value found:
59
- if ( throwErrorIfNotFound && ! isTestEnvironment ) {
60
- throw new Error ( notFoundMessage ) ;
61
- }
55
+ // warn or continue if no value found:
62
56
if ( warn ) {
63
57
console . warn ( notFoundMessage ) ;
64
58
}
0 commit comments