{"record":{"id":"b88fccb8800a6bf6","repo":"apache/answer","slug":"get-config-failed-w-b88fcc","errorCode":null,"errorMessage":"get config failed: %w","messagePattern":"get config failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/migrations/v11.go","lineNumber":45,"sourceCode":"\t\"github.com/segmentfault/pacman/log\"\n\t\"xorm.io/xorm\"\n)\n\nfunc updateRolePinAndHideFeatures(ctx context.Context, x *xorm.Engine) error {\n\tdefaultConfigTable := []*entity.Config{\n\t\t{ID: 119, Key: \"question.pin\", Value: `0`},\n\t\t{ID: 120, Key: \"question.unpin\", Value: `0`},\n\t\t{ID: 121, Key: \"question.show\", Value: `0`},\n\t\t{ID: 122, Key: \"question.hide\", Value: `0`},\n\t\t{ID: 123, Key: \"rank.question.pin\", Value: `-1`},\n\t\t{ID: 124, Key: \"rank.question.unpin\", Value: `-1`},\n\t\t{ID: 125, Key: \"rank.question.show\", Value: `-1`},\n\t\t{ID: 126, Key: \"rank.question.hide\", Value: `-1`},\n\t}\n\tfor _, c := range defaultConfigTable {\n\t\texist, err := x.Context(ctx).Get(&entity.Config{ID: c.ID})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"get config failed: %w\", err)\n\t\t}\n\t\tif exist {\n\t\t\tif _, err = x.Context(ctx).Update(c, &entity.Config{ID: c.ID}); err != nil {\n\t\t\t\tlog.Errorf(\"update %+v config failed: %s\", c, err)\n\t\t\t\treturn fmt.Errorf(\"update config failed: %w\", err)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tif _, err = x.Context(ctx).Insert(&entity.Config{ID: c.ID, Key: c.Key, Value: c.Value}); err != nil {\n\t\t\tlog.Errorf(\"insert %+v config failed: %s\", c, err)\n\t\t\treturn fmt.Errorf(\"add config failed: %w\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":27,"sourceCodeEnd":62,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/migrations/v11.go#L27-L62","documentation":"This error is returned by the updateRolePinAndHideFeatures migration in internal/migrations/v11.go when the xorm Get() lookup of an existing config row (checking whether config ID like 125/126 exists) fails at the database level. The migration wraps the raw driver error with %w so the underlying cause (connection failure, locked table, bad schema) is preserved. It is thrown before any insert/update is attempted for that config row.","triggerScenarios":"x.Context(ctx).Get(&entity.Config{ID: c.ID}) returns a non-nil err while iterating defaultConfigTable during the v11 migration run.","commonSituations":"Database unreachable or credentials wrong during upgrade; config table missing or corrupted; DB connection dropped mid-migration; read-only replica; table lock held by a concurrent migration.","solutions":["Check DB connectivity and credentials, then re-run the migration (migrations are typically idempotent)","Inspect the wrapped cause (%w) in the error chain to see the driver-specific message","Verify the config table exists and has the expected schema (id, key, value columns)","Check server logs around the migration for lock timeouts or connection resets"],"exampleFix":"// before\nexist, err := x.Context(ctx).Get(&entity.Config{ID: c.ID})\nif err != nil {\n\treturn fmt.Errorf(\"get config failed: %w\", err)\n}\n// after (add retry for transient connection issues)\nexist, err := x.Context(ctx).Get(&entity.Config{ID: c.ID})\nif err != nil {\n\tif isTransientDBError(err) {\n\t\ttime.Sleep(time.Second)\n\t\texist, err = x.Context(ctx).Get(&entity.Config{ID: c.ID})\n\t}\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get config failed: %w\", err)\n\t}\n}","handlingStrategy":"retry","validationCode":"// before running the migration\nif err := db.Ping(); err != nil {\n\treturn fmt.Errorf(\"database not reachable: %w\", err)\n}\nif _, err := db.Exec(\"SELECT 1 FROM config LIMIT 1\"); err != nil {\n\treturn fmt.Errorf(\"config table unreadable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := runMigrations(); err != nil {\n\tvar wrapped interface{ Unwrap() error }\n\tif errors.As(err, &target) { log.Fatalf(\"migration failed, cause: %v\", target) }\n}","preventionTips":["Back up the database before every upgrade","Verify DB connectivity and privileges before starting migrations","Take one DB user dedicated to migrations with full DML rights","Retry migrations after transient failures; they are idempotent"],"tags":["database","migration","xorm","config"],"backgroundTag":"migration-db-query-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"}