apache/answer · error

get config failed: %w

Error message

get config failed: %w

What it means

Returned by defaultLoginConfig in internal/cli/config.go when the xorm query x.Get(loginSiteInfo) — fetching the SiteInfo row of type SiteTypeLogin — fails at the database level. This is a CLI maintenance command (SetDefaultConfig) that flips allow_password_login to true; the failure means the DB could not execute the SELECT, not that the row is absent (absence just returns exist=false). The driver error is wrapped via %w.

Source

Thrown at internal/cli/config.go:78

	if field.AllowPasswordLogin {
		return defaultLoginConfig(db)
	}
	if len(field.DeactivatePluginSlugName) > 0 {
		return deactivatePlugin(db, field.DeactivatePluginSlugName)
	}

	return nil
}

func defaultLoginConfig(x *xorm.Engine) (err error) {
	fmt.Println("set default login config")

	loginSiteInfo := &entity.SiteInfo{
		Type: constant.SiteTypeLogin,
	}
	exist, err := x.Get(loginSiteInfo)
	if err != nil {
		return fmt.Errorf("get config failed: %w", err)
	}
	if exist {
		var content map[string]any
		_ = json.Unmarshal([]byte(loginSiteInfo.Content), &content)
		content["allow_password_login"] = true
		dataByte, _ := json.Marshal(content)
		loginSiteInfo.Content = string(dataByte)
		_, err = x.ID(loginSiteInfo.ID).Cols("content").Update(loginSiteInfo)
		if err != nil {
			return fmt.Errorf("update site info failed: %w", err)
		}
	}
	return nil
}

func deactivatePlugin(x *xorm.Engine, pluginSlugName string) (err error) {
	fmt.Printf("try to deactivate plugin: %s\n", pluginSlugName)

View on GitHub (pinned to 3b9f137061)

Solutions

  1. Inspect the wrapped driver error to distinguish connection failure vs missing table
  2. Verify the DSN/host/port/credentials used to build the xorm.Engine point at the intended database
  3. Run pending migrations so the site_info table and SiteTypeLogin row exist
  4. If the DB is in Docker, ensure it is healthy and reachable from the CLI process before running the command
Defensive patterns

Strategy: try-catch

Validate before calling

// verify DB reachability before running the config command
sqlDB, _ := db.DB()
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
if err := sqlDB.PingContext(ctx); err != nil {
    return fmt.Errorf("database unreachable: %w", err)
}

Try / catch

if err := cli.SetDefaultConfig(field); err != nil {
    if errors.Is(err, sql.ErrNoRows) || strings.Contains(err.Error(), "doesn't exist") {
        log.Printf("site_info table missing — run migrations first")
    }
    return err
}

Prevention

When it happens

Trigger: SetDefaultConfig runs with --allow-password-login while the database is unreachable, credentials in the connection DSN are wrong, the site_info table does not exist (migrations not applied), or the DB connection was closed/timed out.

Common situations: Running the config CLI against the wrong environment's DB; a version upgrade where the site_info table schema changed; Docker containers where the app starts before the database is ready.

Related errors


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