gastownhall/beads · error

SetMetadata: %w

Error message

SetMetadata: %w

What it means

This is a wrapping error from ConfigUseCaseImpl.SetMetadata in internal/storage/domain/config.go:234. The use case delegated a metadata write to the config repository (cfgRepo.SetMetadata) and the repository returned an error; the use case re-wraps it with a 'SetMetadata:' prefix while preserving the original cause via %w. The real failure (DB unavailable, constraint, context cancelled) is inside the wrapped chain.

Source

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

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

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 {

View on GitHub (pinned to 71377f2769)

Solutions

  1. Inspect the wrapped cause with errors.Unwrap / %v of the full chain to find the storage-level error
  2. Verify the database is reachable and not locked (start/repair the Dolt/SQL backend)
  3. Retry the SetMetadata call once the storage layer is healthy
  4. Check that the key/value conform to any repository-level constraints

Example fix

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

Strategy: try-catch

Validate before calling

// verify storage is reachable before writing metadata
if err := pingStore(ctx); err != nil {
	return fmt.Errorf("storage unavailable, skipping SetMetadata: %w", err)
}

Try / catch

err := uc.SetMetadata(ctx, key, value)
if err != nil {
	var wrapped error
	if errors.Unwrap(err) != nil {
		wrapped = errors.Unwrap(err)
	}
	log.Printf("SetMetadata failed for key %q: %v (cause: %v)", key, err, wrapped)
	return err
}

Prevention

When it happens

Trigger: Calling SetMetadata(ctx, key, value) on the config use case when the underlying config repository write fails — e.g. database connection error, Dolt/SQL failure, read-only store, or expired/cancelled context.

Common situations: DB not running or unreachable during bd commands; writing metadata in a corrupted or migrated-incompatible database; context deadline exceeded on slow storage; attempting writes on a read-only replica.

Related errors


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