{"record":{"id":"f44bd91f3d4b5308","repo":"jdx/mise","slug":"invalid-database-name","errorCode":null,"errorMessage":"invalid database name","messagePattern":"invalid database name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/daemons/presets.rs","lineNumber":234,"sourceCode":"        .prefix(\".mise-init-\")\n        .tempdir_in(parent)?;\n    let staged_data: PathBuf = staging.path().join(\"data\");\n    if preset_name == \"postgres\" {\n        let status = Command::new(\"initdb\")\n            .args([\"-D\"])\n            .arg(&staged_data)\n            .args([\"-U\", \"postgres\", \"--auth=trust\"])\n            .status()?;\n        if !status.success() {\n            bail!(\"Postgres initialization failed; existing data was preserved\");\n        }\n        if database != \"postgres\" {\n            if database.is_empty()\n                || !database\n                    .chars()\n                    .all(|c| c.is_ascii_alphanumeric() || c == '_')\n            {\n                bail!(\"invalid database name\");\n            }\n            let mut child = Command::new(\"postgres\")\n                .arg(\"--single\")\n                .arg(\"-D\")\n                .arg(&staged_data)\n                .arg(\"postgres\")\n                .stdin(Stdio::piped())\n                .spawn()?;\n            writeln!(\n                child.stdin.take().unwrap(),\n                \"CREATE DATABASE \\\"{database}\\\";\"\n            )?;\n            if !child.wait()?.success() {\n                bail!(\"failed to create database {database}\");\n            }\n        }\n        if std::fs::read_to_string(staged_data.join(\"PG_VERSION\"))?.trim() != major {\n            bail!(\"initdb and postgres have incompatible versions\");","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/daemons/presets.rs#L216-L252","documentation":"For non-default databases, initialize re-validates the database name (non-empty, ASCII alphanumeric/underscore) before running `postgres --single` to create it, then bails with this terse message if the check fails. This is a second, stricter guard inside the staged init path.","triggerScenarios":"A database name that passed earlier contexts but is empty or contains characters outside [A-Za-z0-9_] reaches the create-database step during initialize.","commonSituations":"Programmatically generated database names with hyphens or dots; whitespace-only names; config where the earlier expand check was bypassed by calling initialize directly.","solutions":["Change the configured database name to only letters, numbers, and underscores","Ensure the name is non-empty","Fix the generator/template that produced the invalid name"],"exampleFix":"# before\ndatabase = \"app.db\"\n# after\ndatabase = \"app_db\"","handlingStrategy":"validation","validationCode":"const validDb = (db) => typeof db === 'string' && /^[A-Za-z0-9_]+$/.test(db);","typeGuard":"const isSafeDbName = (v) => typeof v === 'string' && /^[A-Za-z0-9_]+$/.test(v);","tryCatchPattern":null,"preventionTips":["Constrain generated database names to [A-Za-z0-9_]","Sanitize names derived from branch names or hostnames before use","Prefer snake_case identifiers"],"tags":["daemon","postgres","validation","naming"],"backgroundTag":"invalid-identifier-format","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}