diff --git a/lib/EnvError.ts b/lib/EnvError.ts index 75b3d8f..73704c0 100644 --- a/lib/EnvError.ts +++ b/lib/EnvError.ts @@ -1,15 +1,15 @@ import { EnvSchemaValue } from './types'; export enum EnvErrorType { - MISSING, - WRONG_TYPE, + MISSING = 'MISSING', + WRONG_TYPE = 'WRONG_TYPE', } export type EnvErrorReport = { [key: string]: { type: EnvErrorType; schemaValue: EnvSchemaValue; - value?: string; + receivedValue?: string; }; }; @@ -26,8 +26,8 @@ export class EnvError extends Error { function formatReport(report: EnvErrorReport) { const errors = Object.entries(report).map(entry => { - const [key, { type, schemaValue, value }] = entry; - return formatError(key, type, schemaValue, value); + const [key, { type, schemaValue, receivedValue }] = entry; + return formatError(key, type, schemaValue, receivedValue); }); return `Invalid or missing environment variables\n - ${errors.join('\n - ')}\n`; } diff --git a/lib/validate.ts b/lib/validate.ts index 140232b..0f93018 100644 --- a/lib/validate.ts +++ b/lib/validate.ts @@ -36,7 +36,7 @@ function validateSchema(schema: EnvSchema, env: Env): EnvErrorReport | null { report[key] = { type: EnvErrorType.WRONG_TYPE, schemaValue, - value, + receivedValue: value, }; } } diff --git a/tests/__snapshots__/validate.test.ts.snap b/tests/__snapshots__/validate.test.ts.snap index 9902fe2..52c7335 100644 --- a/tests/__snapshots__/validate.test.ts.snap +++ b/tests/__snapshots__/validate.test.ts.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`validate reporting should report badly typed variables 1`] = ` -"EnvError: Invalid or missing environment variables +"Invalid or missing environment variables - Expected value for key 'BOOLEAN' of type Boolean; got '123' - Expected value for key 'NUMBER' of type Number; got 'abc' - Expected value for key 'REGEXP' to match /abc/; got 'true' @@ -9,7 +9,7 @@ exports[`validate reporting should report badly typed variables 1`] = ` `; exports[`validate reporting should report missing variables 1`] = ` -"EnvError: Invalid or missing environment variables +"Invalid or missing environment variables - Expected value for key 'MISSING'; none found " `;