hcengineering/platform · error · Error

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

Error message

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

What it means

The analytics-collector config IIFE requires the 'Secret' and 'AccountsUrl' params (checked against requiredParams) and throws 'Missing config for attributes' when either is undefined. This ensures the collector can authenticate incoming events and talk to the accounts service.

Source

Thrown at services/analytics-collector/pod-analytics-collector/src/config.ts:48

const parseNumber = (str: string | undefined): number | undefined => (str !== undefined ? Number(str) : undefined)

const config: Config = (() => {
  const params: Partial<Config> = {
    Port: parseNumber(process.env.PORT) ?? 4007,
    Secret: process.env.SECRET,
    ServiceID: process.env.SERVICE_ID ?? 'analytics-collector-service',
    AccountsUrl: process.env.ACCOUNTS_URL,
    PostHogHost: process.env.POSTHOG_HOST,
    PostHogAPI: process.env.POSTHOG_API_KEY,
    MaxPayloadSize: process.env.MAX_PAYLOAD_SIZE ?? '10mb'
  }

  const requiredParams = ['Secret', 'AccountsUrl'] as Array<keyof Config>

  const missingEnv = requiredParams.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 SECRET and ACCOUNTS_URL in the collector's environment.
  2. Verify the Secret object holding SECRET is mounted and key names match exactly.
  3. Add ACCOUNTS_URL to the service ConfigMap/env block.
  4. Use the same SECRET value as the accounts service, otherwise authenticated requests will later fail.

Example fix

// before
env: { PORT: "4007" }  # SECRET/ACCOUNTS_URL absent
// after
env:
  - name: SECRET
    valueFrom: { secretKeyRef: { name: huly-secret, key: SECRET } }
  - name: ACCOUNTS_URL
    value: https://accounts.example.com
Defensive patterns

Strategy: validation

Validate before calling

const missing = ['SECRET', 'ACCOUNTS_URL'].filter((k) => process.env[k] === undefined)
if (missing.length > 0) throw new Error(`Missing config for attributes: ${missing.join(', ')}`)

Type guard

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

Try / catch

try {
  const { default: config } = await import('./config.js')
} catch (err) {
  if ((err as Error).message.startsWith('Missing config for attributes:')) {
    console.error('analytics-collector config error:', err.message)
    process.exit(1)
  }
  throw err
}

Prevention

When it happens

Trigger: Importing services/analytics-collector/pod-analytics-collector/src/config.ts without SECRET or ACCOUNTS_URL env vars set. The message names the attribute(s): 'Secret' and/or 'AccountsUrl'.

Common situations: Deploying analytics-collector without the shared SECRET; forgetting ACCOUNTS_URL when accounts runs at a custom endpoint; secret not mounted or renamed in the deployment manifest.

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/315937fd513fe4a7. Report an issue: GitHub.