{"record":{"id":"1706bb793fcac4dc","repo":"apache/answer","slug":"get-config-failed-w","errorCode":null,"errorMessage":"get config failed: %w","messagePattern":"get config failed: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cli/config.go","lineNumber":78,"sourceCode":"\tif field.AllowPasswordLogin {\n\t\treturn defaultLoginConfig(db)\n\t}\n\tif len(field.DeactivatePluginSlugName) > 0 {\n\t\treturn deactivatePlugin(db, field.DeactivatePluginSlugName)\n\t}\n\n\treturn nil\n}\n\nfunc defaultLoginConfig(x *xorm.Engine) (err error) {\n\tfmt.Println(\"set default login config\")\n\n\tloginSiteInfo := &entity.SiteInfo{\n\t\tType: constant.SiteTypeLogin,\n\t}\n\texist, err := x.Get(loginSiteInfo)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get config failed: %w\", err)\n\t}\n\tif exist {\n\t\tvar content map[string]any\n\t\t_ = json.Unmarshal([]byte(loginSiteInfo.Content), &content)\n\t\tcontent[\"allow_password_login\"] = true\n\t\tdataByte, _ := json.Marshal(content)\n\t\tloginSiteInfo.Content = string(dataByte)\n\t\t_, err = x.ID(loginSiteInfo.ID).Cols(\"content\").Update(loginSiteInfo)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"update site info failed: %w\", err)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc deactivatePlugin(x *xorm.Engine, pluginSlugName string) (err error) {\n\tfmt.Printf(\"try to deactivate plugin: %s\\n\", pluginSlugName)\n","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/cli/config.go#L60-L96","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the wrapped driver error to distinguish connection failure vs missing table","Verify the DSN/host/port/credentials used to build the xorm.Engine point at the intended database","Run pending migrations so the site_info table and SiteTypeLogin row exist","If the DB is in Docker, ensure it is healthy and reachable from the CLI process before running the command"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// verify DB reachability before running the config command\nsqlDB, _ := db.DB()\nctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)\ndefer cancel()\nif err := sqlDB.PingContext(ctx); err != nil {\n    return fmt.Errorf(\"database unreachable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := cli.SetDefaultConfig(field); err != nil {\n    if errors.Is(err, sql.ErrNoRows) || strings.Contains(err.Error(), \"doesn't exist\") {\n        log.Printf(\"site_info table missing — run migrations first\")\n    }\n    return err\n}","preventionTips":["Ping the database before executing CLI config commands","Apply schema migrations before running maintenance commands","Use healthcheck-gated startup (depends_on: condition: service_healthy) for DB-backed CLIs","Double-check the DSN targets the intended environment"],"tags":["go","database","xorm","config"],"backgroundTag":"database-connection-failed","analyzedSha":"3b9f1370612e690a0b7f230f05e688930db4c6d3","analyzedAt":"2026-09-05T18:18:39.533Z","contentChangedAt":"2026-09-05T18:18:39.533Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}