apache/answer · error

get config failed: %w

Error message

get config failed: %w

What it means

Returned by addGravatarBaseURL in internal/migrations/v13.go when the xorm Get() lookup of the users SiteInfo row fails. The migration must read this row to add gravatar_base_url to its JSON content. The driver error is wrapped with %w.

Source

Thrown at internal/migrations/v13.go:63

		updateUserQuestionCount,
		updateUserAnswerCount,
		inBoxData,
	}
	for _, fn := range fns {
		if err := fn(ctx, x); err != nil {
			return err
		}
	}
	return nil
}

func addGravatarBaseURL(ctx context.Context, x *xorm.Engine) error {
	usersSiteInfo := &entity.SiteInfo{
		Type: constant.SiteTypeUsers,
	}
	exist, err := x.Context(ctx).Get(usersSiteInfo)
	if err != nil {
		return fmt.Errorf("get config failed: %w", err)
	}
	if exist {
		content := &schema.SiteUsersReq{}
		_ = json.Unmarshal([]byte(usersSiteInfo.Content), content)
		content.GravatarBaseURL = "https://www.gravatar.com/avatar/"
		data, _ := json.Marshal(content)
		usersSiteInfo.Content = string(data)

		_, err = x.Context(ctx).ID(usersSiteInfo.ID).Cols("content").Update(usersSiteInfo)
		if err != nil {
			return fmt.Errorf("update site info failed: %w", err)
		}
	}
	return nil
}

func addPrivilegeForInviteSomeoneToAnswer(ctx context.Context, x *xorm.Engine) error {
	// add rank for invite to answer

View on GitHub (pinned to 3b9f137061)

Solutions

  1. Check the wrapped driver error for the exact cause
  2. Verify the site_info table exists with the expected schema
  3. Confirm DB connectivity and privileges, then re-run the migration
Defensive patterns

Strategy: validation

Validate before calling

// verify the users site info row exists and is readable
row := db.QueryRow("SELECT id FROM site_info WHERE type = 'users' LIMIT 1")
var id int64
if err := row.Scan(&id); err != nil {
	log.Println("users site_info row missing or unreadable:", err)
}

Try / catch

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

Prevention

When it happens

Trigger: x.Context(ctx).Get(usersSiteInfo) where usersSiteInfo = &entity.SiteInfo{Type: constant.SiteTypeUsers} returns non-nil err during the v13 migration.

Common situations: site_info table missing or corrupted; DB unreachable during upgrade; type column mismatch preventing the query from matching/executing.

Related errors


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