MCPcopy Create free account
hub / github.com/alanagoyal/docbase / validateEnvironmentVariables

Function validateEnvironmentVariables

lib/env-validation.ts:13–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11})
12
13export function validateEnvironmentVariables() {
14 try {
15 const env = envSchema.parse(process.env)
16 logger.info('Environment variables validated successfully')
17 return env
18 } catch (error) {
19 if (error instanceof z.ZodError) {
20 const missingVars = error.errors.map(err => `${err.path.join('.')}: ${err.message}`).join(', ')
21 logger.error(`Environment validation failed: ${missingVars}`)
22
23 if (process.env.NODE_ENV === 'production') {
24 throw new Error(`Required environment variables are missing: ${missingVars}`)
25 } else {
26 logger.warn('Some environment variables are missing, but continuing in development mode')
27 }
28 } else {
29 logger.error('Unknown error during environment validation', error)
30 throw error
31 }
32 }
33}
34
35export type ValidatedEnv = z.infer<typeof envSchema>

Callers 1

RootLayoutFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected