apache/answer · error
get config failed: %w
Error message
get config failed: %w
What it means
Migration addLoginLimitations reads the site_info row of type 'login'. If the xorm Get query errors, it returns 'get config failed: %w'. This is a data-migration failure reading existing login page configuration, not a missing-config case (that is the exist==false path).
Source
Thrown at internal/migrations/v10.go:40
import (
"context"
"encoding/json"
"fmt"
"github.com/apache/answer/internal/base/constant"
"github.com/apache/answer/internal/entity"
"github.com/apache/answer/internal/schema"
"github.com/tidwall/gjson"
"xorm.io/xorm"
)
func addLoginLimitations(ctx context.Context, x *xorm.Engine) error {
loginSiteInfo := &entity.SiteInfo{
Type: constant.SiteTypeLogin,
}
exist, err := x.Context(ctx).Get(loginSiteInfo)
if err != nil {
return fmt.Errorf("get config failed: %w", err)
}
if exist {
content := &schema.SiteLoginReq{}
_ = json.Unmarshal([]byte(loginSiteInfo.Content), content)
content.AllowEmailRegistrations = true
content.AllowEmailDomains = make([]string, 0)
data, _ := json.Marshal(content)
loginSiteInfo.Content = string(data)
_, err = x.Context(ctx).ID(loginSiteInfo.ID).Cols("content").Update(loginSiteInfo)
if err != nil {
return fmt.Errorf("update site info failed: %w", err)
}
}
interfaceSiteInfo := &entity.SiteInfo{
Type: constant.SiteTypeInterface,
}
exist, err = x.Context(ctx).Get(interfaceSiteInfo)View on GitHub (pinned to 3b9f137061)
Solutions
- Check the wrapped DB error for the underlying cause
- Ensure all earlier migrations (v1–v9) completed so site_info exists
- Verify SELECT privileges on site_info
- Re-run Migrate after restoring DB connectivity
Defensive patterns
Strategy: try-catch
Validate before calling
// ensure site_info exists and is readable before v10
if exist, err := engine.IsTableExist(&entity.SiteInfo{}); err != nil || !exist {
return fmt.Errorf("site_info missing; run earlier migrations first")
} Try / catch
if err := migrations.Migrate(db); err != nil {
var wrapped error
if errors.As(err, &wrapped) && strings.Contains(err.Error(), "get config failed") {
log.Errorf("v10 could not read login config: %v", err)
}
return err
} Prevention
- Apply migrations in order; never skip versions
- Confirm site_info table exists before v10
- Use %w wrapping and errors.As to surface root causes
- Backup site_info before running data migrations
When it happens
Trigger: x.Context(ctx).Get(loginSiteInfo) returns a DB error during v10 migration: connection failure, missing site_info table (migration ordering), permission denied, or context cancelled.
Common situations: Running v10 migration against a DB where earlier migrations were skipped or partially applied; DB credentials/permissions changed; network interruption mid-migration.
Related errors
- update site info failed: %w
- insert site info failed: %w
- %s failed: %s
- sync version failed: %v
- get first version failed: %v
AI-assisted analysis of apache/answer@3b9f137061 (2026-09-05).
Data as JSON: /api/errors/44527ef8e9d8d49b.
Report an issue: GitHub.