{"record":{"id":"baeb27681332251a","repo":"gastownhall/beads","slug":"db-getlocalmetadata-s-w","errorCode":null,"errorMessage":"db: GetLocalMetadata %s: %w","messagePattern":"db: GetLocalMetadata (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/db/config.go","lineNumber":54,"sourceCode":"\t}\n\treturn value, nil\n}\n\nfunc (r *configSQLRepositoryImpl) SetMetadata(ctx context.Context, key, value string) error {\n\tif _, err := r.runner.ExecContext(ctx, \"REPLACE INTO metadata (`key`, value) VALUES (?, ?)\", key, value); err != nil {\n\t\treturn fmt.Errorf(\"db: SetMetadata %s: %w\", key, err)\n\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 {","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/db/config.go#L36-L72","documentation":"GetLocalMetadata reads machine-local settings from the local_metadata table (values not synced across machines). As with GetMetadata, an absent key returns \"\", nil; this wrapper fires only when the SELECT fails outright: local_metadata table missing, database locked/corrupt, permission or connection problems, or a cancelled context.","triggerScenarios":"QueryRowContext(\"SELECT value FROM local_metadata WHERE `key` = ?\").Scan errors for any reason other than sql.ErrNoRows — typically a database created before local_metadata existed, a locked/corrupt file, or connectivity loss.","commonSituations":"Older databases not yet migrated to include local_metadata; concurrent access locking the SQLite/Dolt file; running bd where the DB file has wrong permissions.","solutions":["Inspect the wrapped driver error to identify the concrete cause.","Run bd doctor/migrations to create the local_metadata table if missing.","Check file permissions, locks, and connectivity; close competing processes.","Retry transient failures; remember a missing key returns empty string, not this error."],"exampleFix":"// before\nv, err := configRepo.GetLocalMetadata(ctx, \"last_sync\") // legacy DB lacks local_metadata\n// after\nif err := migrate.EnsureSchema(db); err != nil {\n    return err\n}\nv, err := configRepo.GetLocalMetadata(ctx, \"last_sync\")","handlingStrategy":"fallback","validationCode":"if err := runner.PingContext(ctx); err != nil {\n    return fmt.Errorf(\"database unavailable: %w\", err)\n}","typeGuard":"null","tryCatchPattern":"v, err := configRepo.GetLocalMetadata(ctx, key)\nif err != nil {\n    if strings.Contains(err.Error(), \"no such table\") {\n        // migrate: local_metadata table missing in this (legacy) database\n    }\n    return fmt.Errorf(\"local metadata read failed for %s: %w\", key, err)\n}\nif v == \"\" {\n    // key not set locally: fall back to default value\n}","preventionTips":["Run bd doctor/migrations when pointing at pre-existing databases so local_metadata exists.","Don't open the same DB concurrently from multiple processes; close lingering bd sessions.","Check file permissions on the .beads database directory.","Distinguish \"key absent\" (empty string, nil error) from SQL failure in callers."],"tags":["go","sql","metadata","local-state","query-failure"],"backgroundTag":"sql-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}