Skip to content

fix(init): bd init silently corrupts metadata when directory name contains dots (e.g. Julia packages) #3128

@jjgarzella

Description

@jjgarzella

Summary

When bd init is run in a directory whose name contains a dot — common in Julia package development where directories are named like GPUPolynomials.jl — the command appears to succeed but leaves the installation broken. Every subsequent bd command then fails with a cryptic error.

Motivation

Julia packages are conventionally named with a .jl suffix (e.g. GPUPolynomials.jl, Flux.jl, DifferentialEquations.jl). This makes bd init essentially unusable out of the box for Julia developers without knowing about the --prefix flag — and even then, the current error gives no hint that --prefix is the solution.

Minimal Working Example

mkdir GPUPolynomials.jl && cd GPUPolynomials.jl
git init -q
bd init --quiet       # Exit 0 — appears to succeed!
cat .beads/metadata.json | grep dolt_database
# "dolt_database": "GPUPolynomials.jl"   ← dot NOT sanitized
bd list
# Error: failed to open database: invalid database name "GPUPolynomials.jl"

Root Cause

Two bugs in cmd/bd/init.go:

Bug 1 — metadata.json mismatch (line 666):
When computing dbName (lines 430–431), both hyphens and dots are replaced with underscores. But when writing cfg.DoltDatabase to metadata.json, only hyphens are replaced — dots survive. The comment on lines 425–429 explicitly warns these two sanitizations must match, but they don't.

Result: the database is created as GPUPolynomials_jl, but metadata.json records GPUPolynomials.jl. Every subsequent command tries to open a database that doesn't exist.

Bug 2 — unclear error for other invalid characters:
Characters like spaces, @, !, etc. in directory names survive sanitization entirely. The resulting error comes from deep in the storage layer with no hint that --prefix is the fix.

Desired Behavior

bd init should either:

  • Correctly sanitize dots all the way through (fixing the silent corruption), and
  • Fail early with a clear actionable error for characters that can't be sanitized automatically:
Error: directory name "my project" produces an invalid database name "my project".
Re-run with a valid prefix: bd init --prefix <name>

Fix

See the linked PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions