hcengineering/platform · error · Error

Missing env variables: ${missingEnv.join(', ')}

Error message

Missing env variables: ${missingEnv.join(', ')}

What it means

The backup-service config loader validates required service configuration at startup. It builds a Config object from environment variables and throws this error if any entry in the `required` list is undefined. This fail-fast behavior prevents the service from starting with incomplete configuration (e.g. no DB URL or storage config).

Source

Thrown at server/backup-service/src/config.ts:92

    Secret: process.env[envMap.Secret],
    BucketName: process.env[envMap.BucketName] ?? 'backups',
    ServiceID: process.env[envMap.ServiceID] ?? 'backup-service',
    Interval: parseInt(process.env[envMap.Interval] ?? '3600'),
    Timeout: parseInt(process.env[envMap.Timeout] ?? '3600'),
    CoolDown: parseInt(process.env[envMap.CoolDown] ?? '300'),
    DbURL: process.env[envMap.DbURL],
    SkipWorkspaces: process.env[envMap.SkipWorkspaces] ?? '',
    WorkspaceStorage: process.env[envMap.WorkspaceStorage],
    Storage: process.env[envMap.Storage],
    Region: process.env[envMap.Region] ?? '',
    Parallel: parseInt(process.env[envMap.Parallel] ?? '1'),
    KeepSnapshots: parseInt(process.env[envMap.KeepSnapshots] ?? '84')
  }

  const missingEnv = required.filter((key) => params[key] === undefined).map((key) => envMap[key])

  if (missingEnv.length > 0) {
    throw Error(`Missing env variables: ${missingEnv.join(', ')}`)
  }

  return params as Config
}

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Set the env vars named in the error message (it lists the exact missing names like ACCOUNTS_URL, DB_URL).
  2. Check your deployment manifest (k8s env, docker -e, .env file) includes all required vars for backup-service.
  3. If a var like BUCKET_NAME should be optional, add a `??` default and remove it from the `required` array in src/config.ts.
  4. Verify secrets (SECRET) are mounted correctly in your secret manager.

Example fix

// before
ACCOUNTS_URL=https://accounts DB_URL=  # DB_URL empty
// after
ACCOUNTS_URL=https://accounts.example.com
DB_URL=postgresql://user:pass@db:5432/huly
SECRET=...
STORAGE={"kind":"s3",...}
Defensive patterns

Strategy: validation

Validate before calling

const required = ['ACCOUNTS_URL','ACCOUNTS_DB_URL','SECRET','SERVICE_ID','BUCKET_NAME','DB_URL','STORAGE','WORKSPACE_STORAGE']
const missing = required.filter((k) => process.env[k] === undefined)
if (missing.length > 0) throw new Error(`Missing env variables: ${missing.join(', ')}`)

Type guard

function hasEnv(key: string): boolean {
  return process.env[key] !== undefined
}

Try / catch

try {
  await startBackupService()
} catch (err) {
  if ((err as Error).message.startsWith('Missing env variables:')) {
    console.error('Configuration error:', err.message)
    process.exit(1)
  }
  throw err
}

Prevention

When it happens

Trigger: Starting the backup-service without any of the required env vars: ACCOUNTS_URL, ACCOUNTS_DB_URL, SECRET, SERVICE_ID, BUCKET_NAME, DB_URL, STORAGE, WORKSPACE_STORAGE (all listed in `required`, even those with defaults). Thrown from config() at server/backup-service/src/config.ts:92.

Common situations: Deploying via k8s/docker with a partial ConfigMap; forgetting STORAGE or DB_URL; renaming env vars after a service upgrade; running the service locally without a .env file.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/c606a9da8840bb3b. Report an issue: GitHub.