hcengineering/platform · error

Missing config for attributes: ${missingEnv.join(', ')}

Error message

Missing config for attributes: ${missingEnv.join(', ')}

What it means

The preview service (pods/preview) assembles its Config from environment variables and, as a fail-fast check, throws at module load if any required entry is undefined. It never starts the service with incomplete configuration, since previewing depends on storage/workspace/queue settings.

Source

Thrown at pods/preview/src/config.ts:49

}

const config: Config = (() => {
  const params: Partial<Config> = {
    Port: parseInt(process.env.PORT ?? '4040'),
    Secret: process.env.SECRET,
    ServiceID: process.env.SERVICE_ID ?? 'preview',
    Cache: {
      enabled: process.env.CACHE_ENABLED !== 'false',
      cachePath: process.env.CACHE_PATH,
      cacheSize: parseInt(process.env.CACHE_SIZE ?? '1024') * 1024 * 1024,
      gcInterval: parseInt(process.env.CACHE_GC_INTERVAL ?? '300') * 1000
    }
  }

  const missingEnv = (Object.keys(params) as Array<keyof Config>).filter((key) => params[key] === undefined)

  if (missingEnv.length > 0) {
    throw Error(`Missing config for attributes: ${missingEnv.join(', ')}`)
  }

  return params as Config
})()

export default config

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Set the environment variables named in the error message and restart the service
  2. Compare your deployment env against pods/preview/src/config.ts (or its .env-template) for the full required set
  3. Ensure the .env file is mounted/loaded in the container runtime
  4. After platform upgrades, review config.ts changes and add any newly required variables to manifests

Example fix

# before
kubectl set env deploy/preview MONGO_URL=...   # PARTITIONS/STORAGE still missing
# after
kubectl set env deploy/preview MONGO_URL=... STORAGE_URL=... PARTITIONS=1 SECRETS=... TOKENS=...
Defensive patterns

Strategy: validation

Validate before calling

const required = ['MONGO_URL', 'STORAGE_URL', 'SECRETS', 'TOKENS'] // keys from pods/preview Config
const missing = required.filter((k) => process.env[k] === undefined)
if (missing.length > 0) {
  throw new Error(`preview service missing env vars: ${missing.join(', ')}`)
}

Type guard

function envPresent(keys: readonly string[], env: NodeJS.ProcessEnv): env is NodeJS.ProcessEnv & Record<string, string> {
  return keys.every((k) => env[k] !== undefined)
}

Try / catch

let config: Config
try {
  config = (await import('./config')).default
} catch (err) {
  if (err instanceof Error && err.message.startsWith('Missing config for attributes')) {
    console.error('preview startup aborted - fix env:', err.message)
    process.exit(1)
  }
  throw err
}

Prevention

When it happens

Trigger: Starting pods/preview without all required env variables from its Config; new config keys introduced in an upgrade but absent in existing deployment manifests; dotenv/.env not loaded so all lookups return undefined.

Common situations: Upgrading the platform and the deployment was not updated with new required variables; local dev run without the project .env; typo'd or mis-cased env names in Kubernetes yaml.

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/938d8ecd67c35288. Report an issue: GitHub.