{"record":{"id":"def559411857abe1","repo":"slopus/happy","slug":"expand-env-undefined-variables-referenced-in-pro","errorCode":null,"errorMessage":"[EXPAND ENV] Undefined variables referenced in profile environment: ${undefinedVars.join(', ')}","messagePattern":"\\[EXPAND ENV\\] Undefined variables referenced in profile environment: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/happy-cli/src/utils/expandEnvVars.ts","lineNumber":88,"sourceCode":"\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\n    if (undefinedVars.length > 0) {\n        logger.warn(`[EXPAND ENV] Undefined variables referenced in profile environment: ${undefinedVars.join(', ')}`);\n        logger.warn(`[EXPAND ENV] Session may fail to authenticate. Set these in daemon environment before launching:`);\n        undefinedVars.forEach(varName => {\n            logger.warn(`[EXPAND ENV]   ${varName}=<your-value>`);\n        });\n    }\n\n    return expanded;\n}\n","sourceCodeStart":70,"sourceCodeEnd":97,"githubUrl":"https://github.com/slopus/happy/blob/b824cd0a4681d41af631a8e422a813873e4455b0/packages/happy-cli/src/utils/expandEnvVars.ts#L70-L97","documentation":"After expanding all profile environment variables, expandEnvironmentVariables collects references it could not resolve (not present in daemon env and no default). If any exist it logs this warning listing them, plus per-var hints, because the launched session may fail to authenticate.","triggerScenarios":"A profile's env block references e.g. ${API_KEY} or ${DB_URL} that is absent from the daemon's environment (and no ${VAR:-default} fallback) when spawnSession expands the profile.","commonSituations":"Profile copied from a machine where the vars were exported in the shell; daemon started via systemd/docker without those vars; renamed variable in one place but not the other; typos in variable names.","solutions":["Set each listed variable in the daemon environment (env file / systemd Environment / docker -e) and restart the daemon.","Add inline defaults in the profile, e.g. \"REGION\": \"${AWS_REGION:-us-east-1}\".","Fix typos — compare the listed names against `env` in a working shell.","If the daemon was started before you added the vars, restart it so it re-reads the environment."],"exampleFix":"// before (profile env)\n{ \"API_KEY\": \"${API_KEY}\" }\n// after\n{ \"API_KEY\": \"${API_KEY:-fallback-key}\" }  // or set API_KEY in daemon env","handlingStrategy":"validation","validationCode":"// validate every ${VAR} in the profile exists (or has a default) before spawning\nconst text = fs.readFileSync(profilePath, 'utf8');\nfor (const m of text.matchAll(/\\$\\{([A-Z_][A-Z0-9_]*)(?::-([^}]*))?\\}/g)) {\n  if (m[2] === undefined && process.env[m[1]] === undefined) {\n    console.error(`Unresolved env var ${m[1]} — set it in the daemon environment or add a :-default.`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep daemon env definitions in a versioned env file and audit diffs.","Always provide :- defaults for non-critical variables in profile env blocks.","Restart the daemon after adding new env vars so they are inherited.","Test profiles with a dry run and check the [EXPAND ENV] debug logs before production use."],"tags":["env-var","daemon","profile","undefined-variable"],"backgroundTag":"missing-env-var","analyzedSha":"b824cd0a4681d41af631a8e422a813873e4455b0","analyzedAt":"2026-08-31T23:12:36.205Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}