{"record":{"id":"6ec3558e7ffe4291","repo":"louislam/uptime-kuma","slug":"both-envname-and-envname-file-are-set-pleas","errorCode":null,"errorMessage":"Both ${envName} and ${envName}_FILE are set. Please use only one.","messagePattern":"Both (.+?) and (.+?)_FILE are set\\. Please use only one\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/setup-database.js","lineNumber":24,"sourceCode":"const Database = require(\"./database\");\nconst { allowDevAllOrigin, printServerUrls } = require(\"./util-server\");\nconst mysql = require(\"mysql2/promise\");\nconst { isSSL, sslKey, sslCert, sslKeyPassphrase } = require(\"./config\");\nconst https = require(\"https\");\n\n/**\n * Reads a configuration value from an environment variable or a Docker secrets file.\n * If both the direct env var and the _FILE variant are set, an error is thrown.\n * @param {string} envName The base name of the environment variable (e.g., \"UPTIME_KUMA_DB_PASSWORD\")\n * @returns {string|undefined} The value from the env var, file contents (trimmed), or undefined if neither is set\n * @throws {Error} If both the direct env var and the _FILE variant are set\n */\nfunction getEnvOrFile(envName) {\n    const directValue = process.env[envName];\n    const fileValue = process.env[envName + \"_FILE\"];\n\n    if (directValue && fileValue) {\n        throw new Error(`Both ${envName} and ${envName}_FILE are set. Please use only one.`);\n    }\n\n    if (fileValue) {\n        try {\n            return fs.readFileSync(fileValue, \"utf8\").trim();\n        } catch (err) {\n            throw new Error(`Failed to read ${envName}_FILE at ${fileValue}: ${err.message}`);\n        }\n    }\n\n    return directValue;\n}\n\n/**\n *  A standalone express app that is used to setup a database\n *  It is used when db-config.json and kuma.db are not found or invalid\n *  Once it is configured, it will shut down and start the main server\n */","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/louislam/uptime-kuma/blob/6b5ea0155793e666666745fb8d6fef1e829543a2/server/setup-database.js#L6-L42","documentation":"Thrown by getEnvOrFile(envName) in setup-database.js when BOTH the direct environment variable (e.g. UPTIME_KUMA_DB_PASSWORD) and its Docker-secrets variant with the _FILE suffix are set simultaneously. The helper disallows ambiguity: only one source of a config value is permitted.","triggerScenarios":"Container/host environment exports both UPTIME_KUMA_DB_PASSWORD and UPTIME_KUMA_DB_PASSWORD_FILE (or any envName handled via getEnvOrFile). Detected at startup before the database setup express app can proceed, blocking boot.","commonSituations":"Docker compose file sets the password directly and also mounts a Docker secret with the same suffix; CI secret manager injects both forms; legacy .env left in place after migrating to _FILE secrets.","solutions":["Remove one of the two variables from the environment (docker-compose env/compose env_file, Kubernetes secret/envFrom, or shell export).","Keep UPTIME_KUMA_DB_PASSWORD_FILE pointing at /run/secrets/<name> and unset the plain UPTIME_KUMA_DB_PASSWORD.","Restart the container/process so the helper sees only the single source."],"exampleFix":"# before\nenvironment:\n  - UPTIME_KUMA_DB_PASSWORD=kuma\n  - UPTIME_KUMA_DB_PASSWORD_FILE=/run/secrets/db_password\n# after\nenvironment:\n  - UPTIME_KUMA_DB_PASSWORD_FILE=/run/secrets/db_password","handlingStrategy":"validation","validationCode":"// Startup guard before booting the app\nfunction assertNoDuplicateEnv(envName) {\n  if (process.env[envName] && process.env[envName + \"_FILE\"]) {\n    throw new Error(`Unset one of ${envName} / ${envName}_FILE before starting.`);\n  }\n}\n[\"UPTIME_KUMA_DB_PASSWORD\", \"UPTIME_KUMA_DB_USERNAME\"].forEach(assertNoDuplicateEnv);","typeGuard":"function isSingleEnvSource(envName) {\n  const d = process.env[envName], f = process.env[envName + \"_FILE\"];\n  return !(d && f);\n}","tryCatchPattern":"try {\n  require(\"./setup-database\");\n} catch (e) {\n  if (/Both .* and .*_FILE are set/.test(e.message)) {\n    failDeployment(\"Remove one of the duplicate env vars in compose/manifest.\");\n  } else throw e;\n}","preventionTips":["Standardize on _FILE secrets for Docker/K8s and never set the plain variable.","Audit compose/env files for both keys before deploy.","Add a CI lint step that rejects both keys being set."],"tags":["config","environment","docker-secrets","startup","database"],"backgroundTag":null,"analyzedSha":"6b5ea0155793e666666745fb8d6fef1e829543a2","analyzedAt":"2026-08-12T23:42:12.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}