apache/answer · error

update config failed: %w

Error message

update config failed: %w

What it means

Returned by addPrivilegeForInviteSomeoneToAnswer when the xorm Update() of the existing config ID 127 row fails. The existence check succeeded; the write of the privilege value (1000) errored. The driver error is wrapped with %w.

Source

Thrown at internal/migrations/v13.go:127

			continue
		}
		_, err = x.Context(ctx).Insert(rel)
		if err != nil {
			return err
		}
	}

	defaultConfigTable := []*entity.Config{
		{ID: 127, Key: "rank.answer.invite_someone_to_answer", Value: `1000`},
	}
	for _, c := range defaultConfigTable {
		exist, err := x.Context(ctx).Get(&entity.Config{ID: c.ID})
		if err != nil {
			return fmt.Errorf("get config failed: %w", err)
		}
		if exist {
			if _, err = x.Context(ctx).Update(c, &entity.Config{ID: c.ID}); err != nil {
				return fmt.Errorf("update config failed: %w", err)
			}
			continue
		}
		if _, err = x.Context(ctx).Insert(&entity.Config{ID: c.ID, Key: c.Key, Value: c.Value}); err != nil {
			return fmt.Errorf("add config failed: %w", err)
		}
	}
	return nil
}

func updateQuestionCount(ctx context.Context, x *xorm.Engine) error {
	// question answer count
	answers := make([]AnswerV13, 0)
	err := x.Context(ctx).Find(&answers, &AnswerV13{Status: entity.AnswerStatusAvailable})
	if err != nil {
		return fmt.Errorf("get answers failed: %w", err)
	}
	questionAnswerCount := make(map[string]int)

View on GitHub (pinned to 3b9f137061)

Solutions

  1. Inspect the wrapped driver error for the failing statement
  2. Verify UPDATE privilege on the config table
  3. Re-run the migration after resolving the DB issue
Defensive patterns

Strategy: try-catch

Validate before calling

// verify UPDATE privilege on config before migrating
if _, err := db.Exec("UPDATE config SET value = value WHERE id = -1"); err != nil {
	return fmt.Errorf("no UPDATE privilege on config: %w", err)
}

Try / catch

if err := runMigrations(); err != nil {
	if strings.Contains(err.Error(), "update config failed") {
		log.Fatalf("config update failed, cause: %v", errors.Unwrap(err))
	}
}

Prevention

When it happens

Trigger: x.Context(ctx).Update(c, &entity.Config{ID: c.ID}) returns non-nil err when config row 127 already exists in the v13 migration.

Common situations: Read-only DB user; row locked by concurrent traffic writing user ranks; schema mismatch on the config table; connection reset mid-migration.

Related errors


AI-assisted analysis of apache/answer@3b9f137061 (2026-09-05). Data as JSON: /api/errors/81261dd52e52020c. Report an issue: GitHub.