forked from rolodato/dotenv-safe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMissingEnvVarsError.js
24 lines (21 loc) · 1.1 KB
/
MissingEnvVarsError.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'use strict'
const util = require('util')
function MissingEnvVarsError (allowEmptyValues, dotenvFilename, exampleFilename, missingVars, error) {
const errorMessage = `The following variables were defined in ${exampleFilename} but are not present in the environment/kub.deployment:\n ${missingVars.join(', ')}
Make sure to add them to ${dotenvFilename} or directly to the environment.`
const allowEmptyValuesMessage = !allowEmptyValues ? `If you expect any of these variables to be empty, you can use the allowEmptyValues option:
require('dotenv-safe').config({
allowEmptyValues: true
});` : ''
const envErrorMessage = error ? `Also, the following error was thrown when trying to read variables from ${dotenvFilename}:\n${error.message}` : ''
Error.call(this)
this.name = this.constructor.name
this.missing = missingVars
this.example = this.sample = exampleFilename
this.message = [errorMessage, allowEmptyValuesMessage, envErrorMessage]
.filter(Boolean)
.join('\n\n')
Error.captureStackTrace(this, this.constructor)
}
util.inherits(MissingEnvVarsError, Error)
module.exports = MissingEnvVarsError