{"record":{"id":"5627ed29463c04d8","repo":"gastownhall/beads","slug":"db-setlocalmetadata-s-w","errorCode":null,"errorMessage":"db: SetLocalMetadata %s: %w","messagePattern":"db: SetLocalMetadata (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/db/config.go","lineNumber":61,"sourceCode":"\t}\n\treturn nil\n}\n\nfunc (r *configSQLRepositoryImpl) GetLocalMetadata(ctx context.Context, key string) (string, error) {\n\tvar value string\n\terr := r.runner.QueryRowContext(ctx, \"SELECT value FROM local_metadata WHERE `key` = ?\", key).Scan(&value)\n\tif errors.Is(err, sql.ErrNoRows) {\n\t\treturn \"\", nil\n\t}\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"db: GetLocalMetadata %s: %w\", key, err)\n\t}\n\treturn value, nil\n}\n\nfunc (r *configSQLRepositoryImpl) SetLocalMetadata(ctx context.Context, key, value string) error {\n\tif _, err := r.runner.ExecContext(ctx, \"REPLACE INTO local_metadata (`key`, value) VALUES (?, ?)\", key, value); err != nil {\n\t\treturn fmt.Errorf(\"db: SetLocalMetadata %s: %w\", key, err)\n\t}\n\treturn nil\n}\n\nfunc (r *configSQLRepositoryImpl) GetConfig(ctx context.Context, key string) (string, error) {\n\tvar value string\n\terr := r.runner.QueryRowContext(ctx, \"SELECT value FROM config WHERE `key` = ?\", key).Scan(&value)\n\tif errors.Is(err, sql.ErrNoRows) {\n\t\treturn \"\", nil\n\t}\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"db: GetConfig %s: %w\", key, err)\n\t}\n\treturn value, nil\n}\n\nfunc (r *configSQLRepositoryImpl) SetConfig(ctx context.Context, key, value string) error {\n\tif key == \"issue_prefix\" {","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/db/config.go#L43-L79","documentation":"This error wraps the underlying SQL driver failure from an INSERT/REPLACE into the local_metadata table in the Dolt-backed storage layer. SetLocalMetadata writes a key/value row used for repo-local metadata; when the ExecContext call fails, the error is wrapped as \"db: SetLocalMetadata <key>: <cause>\" so callers know which metadata key could not be persisted. The root cause is always in the wrapped driver error (connection loss, schema problem, constraint, etc.).","triggerScenarios":"Calling SetLocalMetadata(ctx, key, value) when the REPLACE INTO local_metadata statement fails: database file corrupted or locked, local_metadata table missing (schema migration not run), connection dropped mid-write, or a driver-level constraint/IO error.","commonSituations":"Running bd commands against a .beads database whose schema predates the local_metadata table; disk full or database file corrupted after a crash; concurrent access locking the Dolt database; version mismatch where an older binary opens a newer schema.","solutions":["Run the driver's schema/migration path (e.g. `bd doctor` or re-open the repo) to ensure the local_metadata table exists","Inspect the wrapped cause (the %w chain) to identify whether it is I/O, locking, or schema related and fix accordingly","Check disk space and file permissions on the database directory","Ensure no other process holds a conflicting lock on the Dolt database, then retry","If the database is corrupt, restore from backup or re-init the repo"],"exampleFix":"// before\nif _, err := db.Exec(\"REPLACE INTO local_metadata (`key`, value) VALUES (?, ?)\", k, v); err != nil {\n\treturn fmt.Errorf(\"set failed\")\n}\n// after\nif _, err := db.Exec(\"REPLACE INTO local_metadata (`key`, value) VALUES (?, ?)\", k, v); err != nil {\n\treturn fmt.Errorf(\"db: SetLocalMetadata %s: %w\", k, err)\n}","handlingStrategy":"try-catch","validationCode":"if err := doctor.CheckSchema(ctx, repo); err != nil {\n\treturn fmt.Errorf(\"schema not ready for local_metadata: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := repo.SetLocalMetadata(ctx, key, value); err != nil {\n\tvar drv *driver.Error\n\tif errors.As(err, &drv) {\n\t\t// inspect drv for lock/IO/table cause before retrying\n\t}\n\treturn fmt.Errorf(\"persisting %q failed: %w\", key, err)\n}","preventionTips":["Run `bd doctor` after upgrading bd so new metadata tables are created before use","Avoid concurrent bd processes on the same repo or use locking","Monitor disk space where the .beads database lives","Always inspect the wrapped (%w) cause rather than treating all failures alike"],"tags":["database","storage","dolt","write-failed"],"backgroundTag":"sql-write-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}