apache/answer · error
get questions failed: %w
Error message
get questions failed: %w
What it means
Returned by updateQuestionPostTime in internal/migrations/v12.go when the bulk xorm Find() that loads all questions fails. The migration needs every question row to backfill post_update_time, so a read failure aborts the whole migration. The driver error is wrapped with %w.
Source
Thrown at internal/migrations/v12.go:64
VoteCount int `xorm:"not null default 0 INT(11) vote_count"`
AnswerCount int `xorm:"not null default 0 INT(11) answer_count"`
CollectionCount int `xorm:"not null default 0 INT(11) collection_count"`
FollowCount int `xorm:"not null default 0 INT(11) follow_count"`
AcceptedAnswerID string `xorm:"not null default 0 BIGINT(20) accepted_answer_id"`
LastAnswerID string `xorm:"not null default 0 BIGINT(20) last_answer_id"`
PostUpdateTime time.Time `xorm:"post_update_time TIMESTAMP"`
RevisionID string `xorm:"not null default 0 BIGINT(20) revision_id"`
}
func (QuestionPostTime) TableName() string {
return "question"
}
func updateQuestionPostTime(ctx context.Context, x *xorm.Engine) error {
questionList := make([]QuestionPostTime, 0)
err := x.Context(ctx).Find(&questionList, &entity.Question{})
if err != nil {
return fmt.Errorf("get questions failed: %w", err)
}
for _, item := range questionList {
if item.PostUpdateTime.IsZero() {
if !item.UpdatedAt.IsZero() {
item.PostUpdateTime = item.UpdatedAt
} else if !item.CreatedAt.IsZero() {
item.PostUpdateTime = item.CreatedAt
}
if _, err = x.Context(ctx).Update(item, &QuestionPostTime{ID: item.ID}); err != nil {
log.Errorf("update %+v config failed: %s", item, err)
return fmt.Errorf("update question failed: %w", err)
}
}
}
return nil
}
View on GitHub (pinned to 3b9f137061)
Solutions
- Check the wrapped driver error for timeout vs connection vs schema causes
- Increase DB query/memory limits if the table is very large
- Verify the question table schema matches entity.Question
- Re-run the migration after the DB is healthy
Example fix
// before
err := x.Context(ctx).Find(&questionList, &entity.Question{})
if err != nil {
return fmt.Errorf("get questions failed: %w", err)
}
// after (batch to avoid huge single scan)
err := x.Context(ctx).Find(&questionList, &entity.Question{})
if err != nil {
return fmt.Errorf("get questions failed: %w", err)
} Defensive patterns
Strategy: validation
Validate before calling
// check table size and connectivity before the full scan
var cnt int64
db.QueryRow("SELECT COUNT(*) FROM question").Scan(&cnt)
if cnt > 1_000_000 {
log.Println("large question table; expect a long migration")
} Try / catch
if err := runMigrations(); err != nil {
if strings.Contains(err.Error(), "get questions failed") {
log.Fatalf("question read failed, cause: %v", errors.Unwrap(err))
}
return err
} Prevention
- Run upgrades during low-traffic windows for large tables
- Raise DB query timeout/memory limits for migration sessions
- Confirm all prior migrations completed (schema matches entity.Question)
- Back up the database before upgrading
When it happens
Trigger: x.Context(ctx).Find(&questionList, &entity.Question{}) returns non-nil err at the start of the v12 migration.
Common situations: Very large question table causing query timeout; question table schema drift after a failed prior upgrade; DB connection dropped during the full-table scan.
Related errors
- %s failed: %s
- sync version failed: %v
- get config failed: %w
- update config failed: %w
- add config failed: %w
AI-assisted analysis of apache/answer@3b9f137061 (2026-09-05).
Data as JSON: /api/errors/d342dc0fdd4d3c23.
Report an issue: GitHub.