jdx/mise · error

invalid database name

Error message

invalid database name

What it means

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.

Solutions

  1. Change the configured database name to only letters, numbers, and underscores
  2. Ensure the name is non-empty
  3. Fix the generator/template that produced the invalid name

Example fix

# before
database = "app.db"
# after
database = "app_db"
Defensive patterns

Strategy: validation

Validate before calling

const validDb = (db) => typeof db === 'string' && /^[A-Za-z0-9_]+$/.test(db);

Type guard

const isSafeDbName = (v) => typeof v === 'string' && /^[A-Za-z0-9_]+$/.test(v);

Prevention

When it happens

Trigger: 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.

Common situations: Programmatically generated database names with hyphens or dots; whitespace-only names; config where the earlier expand check was bypassed by calling initialize directly.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/f44bd91f3d4b5308. Report an issue: GitHub.

Appendix: source

Thrown at src/daemons/presets.rs:234

        .prefix(".mise-init-")
        .tempdir_in(parent)?;
    let staged_data: PathBuf = staging.path().join("data");
    if preset_name == "postgres" {
        let status = Command::new("initdb")
            .args(["-D"])
            .arg(&staged_data)
            .args(["-U", "postgres", "--auth=trust"])
            .status()?;
        if !status.success() {
            bail!("Postgres initialization failed; existing data was preserved");
        }
        if database != "postgres" {
            if database.is_empty()
                || !database
                    .chars()
                    .all(|c| c.is_ascii_alphanumeric() || c == '_')
            {
                bail!("invalid database name");
            }
            let mut child = Command::new("postgres")
                .arg("--single")
                .arg("-D")
                .arg(&staged_data)
                .arg("postgres")
                .stdin(Stdio::piped())
                .spawn()?;
            writeln!(
                child.stdin.take().unwrap(),
                "CREATE DATABASE \"{database}\";"
            )?;
            if !child.wait()?.success() {
                bail!("failed to create database {database}");
            }
        }
        if std::fs::read_to_string(staged_data.join("PG_VERSION"))?.trim() != major {
            bail!("initdb and postgres have incompatible versions");

View on GitHub (pinned to 533346cc37)