{"record":{"id":"abaf0fbaa99638c0","repo":"apache/answer","slug":"update-site-info-failed-w-abaf0f","errorCode":null,"errorMessage":"update site info failed: %w","messagePattern":"update site info failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/migrations/v13.go","lineNumber":74,"sourceCode":"\nfunc addGravatarBaseURL(ctx context.Context, x *xorm.Engine) error {\n\tusersSiteInfo := &entity.SiteInfo{\n\t\tType: constant.SiteTypeUsers,\n\t}\n\texist, err := x.Context(ctx).Get(usersSiteInfo)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get config failed: %w\", err)\n\t}\n\tif exist {\n\t\tcontent := &schema.SiteUsersReq{}\n\t\t_ = json.Unmarshal([]byte(usersSiteInfo.Content), content)\n\t\tcontent.GravatarBaseURL = \"https://www.gravatar.com/avatar/\"\n\t\tdata, _ := json.Marshal(content)\n\t\tusersSiteInfo.Content = string(data)\n\n\t\t_, err = x.Context(ctx).ID(usersSiteInfo.ID).Cols(\"content\").Update(usersSiteInfo)\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 addPrivilegeForInviteSomeoneToAnswer(ctx context.Context, x *xorm.Engine) error {\n\t// add rank for invite to answer\n\tpowers := []*entity.Power{\n\t\t{ID: 38, Name: \"invite someone to answer\", PowerType: permission.AnswerInviteSomeoneToAnswer, Description: \"invite someone to answer\"},\n\t}\n\tfor _, power := range powers {\n\t\texist, err := x.Context(ctx).Get(&entity.Power{PowerType: power.PowerType})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif exist {\n\t\t\t_, err = x.Context(ctx).ID(power.ID).Update(power)\n\t\t} else {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/migrations/v13.go#L56-L92","documentation":"Returned by addGravatarBaseURL when the xorm Update() writing the modified JSON content (with GravatarBaseURL set) back to the users SiteInfo row fails. The read succeeded and the content was unmarshalled/re-marshalled; only the persisted write failed. The driver error is wrapped with %w.","triggerScenarios":"x.Context(ctx).ID(usersSiteInfo.ID).Cols(\"content\").Update(usersSiteInfo) returns non-nil err in the v13 migration.","commonSituations":"Content column size limit exceeded by the larger JSON; row locked by concurrent admin edit; write privileges removed; connection dropped between read and write.","solutions":["Read the wrapped driver error to identify the SQL failure","Verify UPDATE privilege on site_info and adequate column size for content","Re-run the migration; it only writes when the users site info row exists"],"exampleFix":"// before\n_, err = x.Context(ctx).ID(usersSiteInfo.ID).Cols(\"content\").Update(usersSiteInfo)\nif err != nil {\n\treturn fmt.Errorf(\"update site info failed: %w\", err)\n}\n// after (log which row failed)\n_, err = x.Context(ctx).ID(usersSiteInfo.ID).Cols(\"content\").Update(usersSiteInfo)\nif err != nil {\n\treturn fmt.Errorf(\"update site info id=%d failed: %w\", usersSiteInfo.ID, err)\n}","handlingStrategy":"try-catch","validationCode":"// ensure content column can hold the updated JSON\nvar size int\ndb.QueryRow(\"SELECT CHARACTER_MAXIMUM_LENGTH FROM information_schema.columns WHERE table_name='site_info' AND column_name='content'\").Scan(&size)\n// ensure size is large enough (e.g. TEXT not VARCHAR(255))","typeGuard":null,"tryCatchPattern":"if err := runMigrations(); err != nil {\n\tif strings.Contains(err.Error(), \"update site info failed\") {\n\t\tlog.Fatalf(\"site_info write failed, cause: %v\", errors.Unwrap(err))\n\t}\n}","preventionTips":["Use a sufficiently large column type for site_info.content","Avoid concurrent admin edits to site info during upgrades","Grant the migration user UPDATE privileges","Re-run the migration; the write only happens when the row exists"],"tags":["database","migration","xorm","site-info"],"backgroundTag":"migration-db-write-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"}