{"record":{"id":"dc78f782a8c3a139","repo":"hcengineering/platform","slug":"mail-url-env-var-is-not-set","errorCode":null,"errorMessage":"MAIL_URL env var is not set","messagePattern":"MAIL_URL env var is not set","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"services/mail/pod-mail-worker/src/config.ts","lineNumber":72,"sourceCode":"    if (process.env.KVS_URL !== undefined) {\n      return process.env.KVS_URL\n    }\n    throw Error('KVS_URL env var is not set')\n  })(),\n  queueConfig: (() => {\n    if (process.env.QUEUE_CONFIG !== undefined) {\n      return process.env.QUEUE_CONFIG\n    }\n    throw Error('QUEUE_CONFIG env var is not set')\n  })(),\n  queueRegion: process.env.QUEUE_REGION ?? '',\n  communicationTopic: process.env.COMMUNICATION_TOPIC ?? 'hulygun',\n  serviceId: process.env.SERVICE_ID ?? 'huly-mail',\n  mailUrl: (() => {\n    if (process.env.MAIL_URL !== undefined) {\n      return process.env.MAIL_URL\n    }\n    throw Error('MAIL_URL env var is not set')\n  })(),\n  mailAuth: process.env.MAIL_AUTH ?? '',\n  footerMessage: process.env.FOOTER_MESSAGE ?? '<br><br><p>Sent via <a href=\"https://huly.io\">Huly</a></p>',\n  outgoingSyncStartDate: new Date(process.env.OUTGOING_SYNC_START_DATE ?? '2025-08-20T00:00:00.000Z')\n}\n\nexport default config\n","sourceCodeStart":54,"sourceCodeEnd":80,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/services/mail/pod-mail-worker/src/config.ts#L54-L80","documentation":"At startup, pod-mail-worker's config.ts builds a config object and requires MAIL_URL to be present in the environment. Unlike most settings in this file, MAIL_URL has no default value, so if it is undefined an Error('MAIL_URL env var is not set') is thrown during module initialization, crashing the worker before it starts.","triggerScenarios":"Running the mail-worker service without MAIL_URL set in the environment (e.g. docker-compose / k8s manifest / .env omitting it, or a typo like MAILURL).","commonSituations":"Deploying the Huly mail worker fresh without copying the full example env file; renaming the variable in one deployment tool but not another; running the service locally outside the dev container that normally provides MAIL_URL.","solutions":["Set MAIL_URL to the mail service endpoint (e.g. the pod-mail service URL) in the worker's environment before startup.","If using docker/k8s, add MAIL_URL to the env section or secret and redeploy.","If running locally, export MAIL_URL=... in your shell or add it to your .env file.","Check for typos in the variable name (must be exactly MAIL_URL)."],"exampleFix":"// before (missing)\n# docker-compose.yml\nmail-worker:\n  environment:\n    - SERVICE_ID=huly-mail\n// after\nmail-worker:\n  environment:\n    - SERVICE_ID=huly-mail\n    - MAIL_URL=http://pod-mail:4001","handlingStrategy":"validation","validationCode":"// Run before starting the mail worker\nconst required = ['MAIL_URL'];\nconst missing = required.filter((k) => process.env[k] === undefined || process.env[k] === '');\nif (missing.length > 0) {\n  throw new Error(`Missing required env vars: ${missing.join(', ')}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await import('./config');\n  startWorker();\n} catch (err) {\n  if (err instanceof Error && err.message.includes('env var')) {\n    console.error(`Environment misconfiguration: ${err.message}`);\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Validate the full required env set in CI and at container startup before the app runs.","Use a checked-in .env.example listing MAIL_URL and diff real envs against it.","In docker-compose/k8s, declare MAIL_URL explicitly in env/secret mappings so omissions are visible.","Prefer a schema validator (zod, envalid) over ad-hoc env reads."],"tags":["env","configuration","startup","mail"],"backgroundTag":"missing-env-var","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}