{"record":{"id":"c1e8e6b75283ed99","repo":"hcengineering/platform","slug":"workspace-url-env-var-is-not-set","errorCode":null,"errorMessage":"WORKSPACE_URL env var is not set","messagePattern":"WORKSPACE_URL env var is not set","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"services/mail/pod-mail-worker/src/config.ts","lineNumber":47,"sourceCode":"  queueConfig: string\n  queueRegion: string\n  communicationTopic: string\n  serviceId: string\n  mailUrl: string\n  mailAuth: string\n  footerMessage: string\n  outgoingSyncStartDate: Date // ISO date string - messages from mail channel before this date will not attempt to be sent to Gmail\n}\n\nconst config: Config = {\n  port: parseInt(process.env.PORT ?? '4050'),\n  secret: process.env.SECRET ?? 'secret',\n  accountsUrl: process.env.ACCOUNTS_URL ?? 'http://localhost:3000',\n  workspaceUrl: (() => {\n    if (process.env.WORKSPACE_URL !== undefined) {\n      return process.env.WORKSPACE_URL\n    }\n    throw Error('WORKSPACE_URL env var is not set')\n  })(),\n  ignoredAddresses: process.env.IGNORED_ADDRESSES?.split(',') ?? [],\n  hookToken: process.env.HOOK_TOKEN,\n  mailSizeLimit: process.env.MAIL_SIZE_LIMIT ?? '50mb',\n  storageConfig: process.env.STORAGE_CONFIG,\n  kvsUrl: (() => {\n    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 ?? '',","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/services/mail/pod-mail-worker/src/config.ts#L29-L65","documentation":"The mail worker config module (services/mail/pod-mail-worker/src/config.ts) resolves workspaceUrl via an inline IIFE that returns process.env.WORKSPACE_URL only when defined, and otherwise throws this error. Unlike most settings in that file which have defaults, WORKSPACE_URL is mandatory because the worker must know the workspace (Huly) service address to function.","triggerScenarios":"process.env.WORKSPACE_URL is undefined when config.ts is imported (module-load time). It only checks `undefined`, so an empty string would NOT throw here — it would be accepted.","commonSituations":"Mail worker pod deployed without WORKSPACE_URL; internal service DNS/name changed and the var was dropped; local development without the full set of required mail-worker vars.","solutions":["Set WORKSPACE_URL to the workspace service URL (e.g. http://workspace:3000 or the public workspace endpoint) in the worker's environment.","Verify service discovery/network policy allows the worker to reach that URL.","Run the worker locally with a .env containing WORKSPACE_URL to confirm startup.","Consider aligning this file's style with the other services' single missingEnv check to get all missing vars reported at once."],"exampleFix":"// before\nWORKSPACE_URL unset -> throw at import\n// after\n# .env\nWORKSPACE_URL=http://workspace:3000","handlingStrategy":"validation","validationCode":"const required = ['WORKSPACE_URL', 'KVS_URL', 'QUEUE_CONFIG', 'MAIL_URL'];\nconst missing = required.filter((k) => process.env[k] === undefined);\nif (missing.length) {\n  console.error('Missing mail-worker env vars:', missing.join(', '));\n  process.exit(1);\n}\nnew URL(process.env.WORKSPACE_URL!); // must be a valid URL","typeGuard":"function isDefined<T>(v: T | undefined): v is T {\n  return v !== undefined;\n}","tryCatchPattern":"try {\n  const { default: config } = await import('./src/config.js');\n} catch (e) {\n  const m = /not set$/.test((e as Error).message) ? 'Set the named env var for the mail worker' : (e as Error).message;\n  console.error(`Mail worker config error: ${m}`);\n  process.exit(1);\n}","preventionTips":["Group all mandatory mail-worker vars (WORKSPACE_URL, KVS_URL, QUEUE_CONFIG, MAIL_URL) into one secret/manifest block.","Validate WORKSPACE_URL is a reachable URL during readiness checks.","Keep .env.example in the repo matching these requirements."],"tags":["environment","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"}