apache/answer · error
update config failed: %w
Error message
update config failed: %w
What it means
Returned by updateRolePinAndHideFeatures when xorm Update() of an existing config row (rank.question.show / rank.question.hide) fails. The row was found via Get(), but persisting the new value errored. The underlying driver error is wrapped with %w.
Source
Thrown at internal/migrations/v11.go:50
defaultConfigTable := []*entity.Config{
{ID: 119, Key: "question.pin", Value: `0`},
{ID: 120, Key: "question.unpin", Value: `0`},
{ID: 121, Key: "question.show", Value: `0`},
{ID: 122, Key: "question.hide", Value: `0`},
{ID: 123, Key: "rank.question.pin", Value: `-1`},
{ID: 124, Key: "rank.question.unpin", Value: `-1`},
{ID: 125, Key: "rank.question.show", Value: `-1`},
{ID: 126, Key: "rank.question.hide", Value: `-1`},
}
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 {
log.Errorf("update %+v config failed: %s", c, err)
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 {
log.Errorf("insert %+v config failed: %s", c, err)
return fmt.Errorf("add config failed: %w", err)
}
}
return nil
}
View on GitHub (pinned to 3b9f137061)
Solutions
- Read the wrapped driver error to identify the exact SQL failure
- Verify the DB user has UPDATE privilege on the config table
- Check for schema mismatches between entity.Config and the actual table
- Re-run the migration after fixing the DB issue; it is safe to retry
Example fix
// before
if _, err = x.Context(ctx).Update(c, &entity.Config{ID: c.ID}); err != nil {
log.Errorf("update %+v config failed: %s", c, err)
return fmt.Errorf("update config failed: %w", err)
}
// after (log the SQL/args for diagnosis)
if _, err = x.Context(ctx).Update(c, &entity.Config{ID: c.ID}); err != nil {
log.Errorf("update config id=%d key=%s failed: %s", c.ID, c.Key, err)
return fmt.Errorf("update config id=%d failed: %w", c.ID, err)
} Defensive patterns
Strategy: try-catch
Validate before calling
// verify write access beforehand
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 write failed, cause: %v", errors.Unwrap(err))
}
return err
} Prevention
- Ensure the migration DB user has UPDATE privileges
- Stop app nodes before running migrations to avoid lock contention
- Back up the config table before upgrading
- Check DB error logs after any failed upgrade
When it happens
Trigger: x.Context(ctx).Update(c, &entity.Config{ID: c.ID}) returns non-nil err for a config row that already exists (exist == true) in the v11 migration.
Common situations: Write permission denied for the DB user; constraint violation on the config table; connection lost between the Get and the Update; DB in read-only mode during maintenance.
Related errors
- update config failed: %w
- %s failed: %s
- sync version failed: %v
- get config failed: %w
- add config failed: %w
AI-assisted analysis of apache/answer@3b9f137061 (2026-09-05).
Data as JSON: /api/errors/750e6b78bae5acf9.
Report an issue: GitHub.