{"record":{"id":"31a184cbdfe3ccab","repo":"gastownhall/beads","slug":"workspace-already-initialized-as-database-q-but-31a184","errorCode":null,"errorMessage":"workspace already initialized as database %q, but --prefix %q was requested.\nRemove --prefix (or pass a matching value) to reuse the existing workspace","messagePattern":"workspace already initialized as database %q, but --prefix %q was requested\\.\nRemove --prefix \\(or pass a matching value\\) to reuse the existing workspace","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/init.go","lineNumber":787,"sourceCode":"\t\t\t\t// benign \"workspace already initialized\" case. An operational\n\t\t\t\t// error from the check (e.g. an unreadable .beads/embeddeddolt\n\t\t\t\t// directory) must still abort rather than be masked as a\n\t\t\t\t// successful skip.\n\t\t\t\tif initIfMissing && errors.Is(err, errWorkspaceAlreadyInitialized) {\n\t\t\t\t\t// Guard against masking a genuine mismatch: an explicit\n\t\t\t\t\t// --prefix or --database that does not match the existing\n\t\t\t\t\t// workspace must abort, since silently skipping would ignore\n\t\t\t\t\t// the request and reuse a different database. --database is\n\t\t\t\t\t// the authoritative selector, so it is checked even when\n\t\t\t\t\t// --prefix is also set.\n\t\t\t\t\texisting := existingWorkspaceDBName()\n\t\t\t\t\tif cmd.Flags().Changed(\"database\") {\n\t\t\t\t\t\tif initIfMissingDatabaseMismatch(existing, database) {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"workspace already initialized as database %q, but --database %q was requested.\\nRemove --database (or pass a matching value) to reuse the existing workspace\", existing, database)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if cmd.Flags().Changed(\"prefix\") {\n\t\t\t\t\t\tif initIfMissingPrefixMismatch(existing, prefix) {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"workspace already initialized as database %q, but --prefix %q was requested.\\nRemove --prefix (or pass a matching value) to reuse the existing workspace\", existing, prefix)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif !quiet {\n\t\t\t\t\t\tfmt.Fprintln(os.Stderr, \"Skipping init: workspace already initialized.\")\n\t\t\t\t\t}\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t\treturn fmt.Errorf(\"%v\", err)\n\t\t\t}\n\t\t}\n\n\t\t// Check BEADS_DB environment variable if --db flag not set\n\t\t// (PersistentPreRun doesn't run for init command)\n\t\tif dbPath == \"\" {\n\t\t\tif envDB := os.Getenv(\"BEADS_DB\"); envDB != \"\" {\n\t\t\t\tdbPath = envDB\n\t\t\t}\n\t\t}","sourceCodeStart":769,"sourceCodeEnd":805,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/init.go#L769-L805","documentation":"Same idempotency guard as the --database variant, but triggered by an explicit --prefix flag that does not match the database already recorded for this workspace. bd init refuses to reuse a workspace whose existing database conflicts with the requested prefix.","triggerScenarios":"`bd init --prefix new_prefix` in an already-initialized workspace where initIfMissingPrefixMismatch(existingWorkspaceDBName(), prefix) is true (and --database was not changed).","commonSituations":"Re-running init after renaming a directory (prefix is often auto-derived from it); scripts passing --prefix from a repo name that differs from the original init; users unaware the workspace is already bound to a database.","solutions":["Remove the --prefix flag to reuse the existing workspace","Or pass a prefix consistent with the existing database shown in the message","If a different database is genuinely wanted, remove .beads and re-init deliberately"],"exampleFix":"// before\nbd init --prefix newproj   # existing db: oldproj\n// after\nbd init --prefix oldproj   # or omit --prefix entirely","handlingStrategy":"validation","validationCode":"[ -d .beads ] && echo \"Already initialized; skipping prefix\" || bd init --prefix \"$PREFIX\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard init scripts with a check for .beads existence","Let prefix auto-derive from the directory instead of forcing --prefix on every run","Align project directory names with the original init prefix to avoid drift"],"tags":["cli","workspace","prefix","idempotency"],"backgroundTag":"workspace-already-initialized","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}