gastownhall/beads · error

SetLocalMetadata: %w

Error message

SetLocalMetadata: %w

What it means

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.

Source

Thrown at internal/storage/domain/config.go:241

func (u *configUseCaseImpl) GetAllConfig(ctx context.Context) (map[string]string, error) {
	out, err := u.cfgRepo.GetAllConfig(ctx)
	if err != nil {
		return nil, fmt.Errorf("GetAllConfig: %w", err)
	}
	return out, nil
}

func (u *configUseCaseImpl) SetMetadata(ctx context.Context, key, value string) error {
	if err := u.cfgRepo.SetMetadata(ctx, key, value); err != nil {
		return fmt.Errorf("SetMetadata: %w", err)
	}
	return nil
}

func (u *configUseCaseImpl) SetLocalMetadata(ctx context.Context, key, value string) error {
	if err := u.cfgRepo.SetLocalMetadata(ctx, key, value); err != nil {
		return fmt.Errorf("SetLocalMetadata: %w", err)
	}
	return nil
}

func (u *configUseCaseImpl) LoadCreateContext(ctx context.Context) (CreateContext, error) {
	prefix, err := u.cfgRepo.GetConfig(ctx, "issue_prefix")
	if err != nil {
		return CreateContext{}, fmt.Errorf("LoadCreateContext: read issue_prefix: %w", err)
	}
	allowed, err := u.cfgRepo.GetAllowedPrefixes(ctx)
	if err != nil {
		return CreateContext{}, fmt.Errorf("LoadCreateContext: read allowed_prefixes: %w", err)
	}
	customTypes, err := u.cfgRepo.GetCustomTypes(ctx)
	if err != nil {
		return CreateContext{}, fmt.Errorf("LoadCreateContext: read custom types: %w", err)
	}
	customStatuses, err := u.cfgRepo.GetCustomStatuses(ctx)

View on GitHub (pinned to 71377f2769)

Solutions

  1. Unwrap the error chain to identify the storage-level cause
  2. Verify the local database file exists and is writable (check directory permissions)
  3. Re-initialize or repair the local store if the file is missing/corrupt
  4. Retry the write after resolving the local storage issue

Example fix

// before
if err := u.cfgRepo.SetLocalMetadata(ctx, key, value); err != nil {
	return fmt.Errorf("SetLocalMetadata: %w", err)
}
// after
if err := u.cfgRepo.SetLocalMetadata(ctx, key, value); err != nil {
	return fmt.Errorf("SetLocalMetadata: set local key %q: %w", key, err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure the local store exists and is writable
if _, err := os.Stat(localDBPath); err != nil {
	return fmt.Errorf("local store missing, run bd init first: %w", err)
}
if err := checkWritable(localDBPath); err != nil {
	return fmt.Errorf("local store not writable: %w", err)
}

Try / catch

err := uc.SetLocalMetadata(ctx, key, value)
if err != nil {
	if isPermissionErr(errors.Unwrap(err)) {
		fixLocalPermissions(localDBPath)
	}
	return fmt.Errorf("local metadata write failed: %w", err)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/6669196ee4a03273. Report an issue: GitHub.