{"record":{"id":"6669196ee4a03273","repo":"gastownhall/beads","slug":"setlocalmetadata-w","errorCode":null,"errorMessage":"SetLocalMetadata: %w","messagePattern":"SetLocalMetadata: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/config.go","lineNumber":241,"sourceCode":"\nfunc (u *configUseCaseImpl) GetAllConfig(ctx context.Context) (map[string]string, error) {\n\tout, err := u.cfgRepo.GetAllConfig(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"GetAllConfig: %w\", err)\n\t}\n\treturn out, nil\n}\n\nfunc (u *configUseCaseImpl) SetMetadata(ctx context.Context, key, value string) error {\n\tif err := u.cfgRepo.SetMetadata(ctx, key, value); err != nil {\n\t\treturn fmt.Errorf(\"SetMetadata: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc (u *configUseCaseImpl) SetLocalMetadata(ctx context.Context, key, value string) error {\n\tif err := u.cfgRepo.SetLocalMetadata(ctx, key, value); err != nil {\n\t\treturn fmt.Errorf(\"SetLocalMetadata: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc (u *configUseCaseImpl) LoadCreateContext(ctx context.Context) (CreateContext, error) {\n\tprefix, err := u.cfgRepo.GetConfig(ctx, \"issue_prefix\")\n\tif err != nil {\n\t\treturn CreateContext{}, fmt.Errorf(\"LoadCreateContext: read issue_prefix: %w\", err)\n\t}\n\tallowed, err := u.cfgRepo.GetAllowedPrefixes(ctx)\n\tif err != nil {\n\t\treturn CreateContext{}, fmt.Errorf(\"LoadCreateContext: read allowed_prefixes: %w\", err)\n\t}\n\tcustomTypes, err := u.cfgRepo.GetCustomTypes(ctx)\n\tif err != nil {\n\t\treturn CreateContext{}, fmt.Errorf(\"LoadCreateContext: read custom types: %w\", err)\n\t}\n\tcustomStatuses, err := u.cfgRepo.GetCustomStatuses(ctx)","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/config.go#L223-L259","documentation":"Wrapping error from ConfigUseCaseImpl.SetLocalMetadata in internal/storage/domain/config.go:241. Identical pattern to SetMetadata but targets the local-scope metadata repository method (SetLocalMetadata), which writes metadata that stays on the local machine rather than syncing. The repository error is preserved with %w under a 'SetLocalMetadata:' prefix.","triggerScenarios":"Calling SetLocalMetadata(ctx, key, value) when the config repository's local metadata write fails — storage I/O error, missing local DB file, permission problem, or cancelled context.","commonSituations":"Local .beads database file missing, corrupted, or locked by another process; permission denied on the local data directory; running bd from a directory without an initialized local store.","solutions":["Unwrap the error chain to identify the storage-level cause","Verify the local database file exists and is writable (check directory permissions)","Re-initialize or repair the local store if the file is missing/corrupt","Retry the write after resolving the local storage issue"],"exampleFix":"// before\nif err := u.cfgRepo.SetLocalMetadata(ctx, key, value); err != nil {\n\treturn fmt.Errorf(\"SetLocalMetadata: %w\", err)\n}\n// after\nif err := u.cfgRepo.SetLocalMetadata(ctx, key, value); err != nil {\n\treturn fmt.Errorf(\"SetLocalMetadata: set local key %q: %w\", key, err)\n}","handlingStrategy":"try-catch","validationCode":"// ensure the local store exists and is writable\nif _, err := os.Stat(localDBPath); err != nil {\n\treturn fmt.Errorf(\"local store missing, run bd init first: %w\", err)\n}\nif err := checkWritable(localDBPath); err != nil {\n\treturn fmt.Errorf(\"local store not writable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"err := uc.SetLocalMetadata(ctx, key, value)\nif err != nil {\n\tif isPermissionErr(errors.Unwrap(err)) {\n\t\tfixLocalPermissions(localDBPath)\n\t}\n\treturn fmt.Errorf(\"local metadata write failed: %w\", err)\n}","preventionTips":["Initialize the local store (bd init) before metadata writes","Check directory permissions on the local data path","Don't hold the local DB open in another process during writes","Unwrap the error to distinguish local-I/O issues from SQL issues"],"tags":["storage","metadata","local","error-wrapping"],"backgroundTag":"metadata-write-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}