{"record":{"id":"d6b4050dcb092f4d","repo":"slopus/happy","slug":"expand-env-warning-varname-is-set-but-empty","errorCode":null,"errorMessage":"[EXPAND ENV] WARNING: ${varName} is set but EMPTY in daemon environment","messagePattern":"\\[EXPAND ENV\\] WARNING: (.+?) is set but EMPTY in daemon environment","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/happy-cli/src/utils/expandEnvVars.ts","lineNumber":68,"sourceCode":"                // Simple ${VAR} reference\n                varName = expr;\n            }\n\n            const resolvedValue = sourceEnv[varName];\n            if (resolvedValue !== undefined) {\n                // Variable found in source environment - use its value\n                // Log for debugging (mask secret-looking values)\n                const isSensitive = varName.toLowerCase().includes('token') ||\n                                   varName.toLowerCase().includes('key') ||\n                                   varName.toLowerCase().includes('secret');\n                const displayValue = isSensitive\n                    ? (resolvedValue ? `<${resolvedValue.length} chars>` : '<empty>')\n                    : resolvedValue;\n                logger.debug(`[EXPAND ENV] Expanded ${varName} from daemon env: ${displayValue}`);\n\n                // Warn if empty string (common mistake)\n                if (resolvedValue === '') {\n                    logger.warn(`[EXPAND ENV] WARNING: ${varName} is set but EMPTY in daemon environment`);\n                }\n\n                return resolvedValue;\n            } else if (defaultValue !== undefined) {\n                // Variable not found but default value provided - use default\n                logger.debug(`[EXPAND ENV] Using default value for ${varName}: ${defaultValue}`);\n                return defaultValue;\n            } else {\n                // Variable not found and no default - keep placeholder and warn\n                undefinedVars.push(varName);\n                return match;\n            }\n        });\n\n        expanded[key] = expandedValue;\n    }\n\n    // Log warning if any variables couldn't be resolved","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/slopus/happy/blob/b824cd0a4681d41af631a8e422a813873e4455b0/packages/happy-cli/src/utils/expandEnvVars.ts#L50-L86","documentation":"expandEnvironmentVariables resolves ${VAR} references in profile environment using the daemon's environment. When a referenced variable IS present in the daemon env but resolves to the empty string, this warning is logged — usually a misconfiguration rather than a genuinely intended empty value.","triggerScenarios":"A profile env value like \"TOKEN=${MY_TOKEN}\" where MY_TOKEN exists in the daemon's process.env but equals \"\" (exported empty in systemd unit, docker ENV FOO=, or a shell profile exporting VAR=).","commonSituations":"Daemon (systemd/launchd/docker) environment defining the var as empty; user edited a dotenv/unit file and left the value blank; secrets manager injected an empty placeholder.","solutions":["Set the variable to a real value in the daemon's environment (systemd Environment=, docker -e, or the daemon's env file) and restart the daemon.","If empty is legitimate, silence by using a default in the profile reference, e.g. ${VAR:-default}.","Check the daemon env with `sudo systemctl show <daemon> -p Environment` or by dumping /proc/<pid>/environ.","Remove the export VAR= line from shell profiles if it was accidental."],"exampleFix":"// before (systemd unit)\nEnvironment=GEMINI_API_KEY=\n// after\nEnvironment=GEMINI_API_KEY=AIza...","handlingStrategy":"validation","validationCode":"for (const v of ['MY_TOKEN', 'GEMINI_API_KEY']) {\n  if (process.env[v] === undefined) console.warn(`${v}: NOT SET in daemon env`);\n  else if (process.env[v] === '') console.warn(`${v}: set but EMPTY — fix daemon env file`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never leave `VAR=` with an empty value in env files/systemd units.","Use ${VAR:-default} references in profile env for optional values.","After editing a daemon env, restart the daemon and re-check.","Inspect actual daemon env via /proc/<pid>/environ when in doubt."],"tags":["env-var","daemon","configuration","empty-value"],"backgroundTag":"missing-env-var","analyzedSha":"b824cd0a4681d41af631a8e422a813873e4455b0","analyzedAt":"2026-08-31T23:12:36.205Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}