{"record":{"id":"5b3703c360386b15","repo":"apache/answer","slug":"update-password-failed-w","errorCode":null,"errorMessage":"update password failed: %w","messagePattern":"update password failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cli/reset_password.go","lineNumber":148,"sourceCode":"\t} else {\n\t\tpassword, err = promptForPassword()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"password input failed: %w\", err)\n\t\t}\n\t}\n\n\tif !confirmAction(fmt.Sprintf(\"This will reset password for user '[%s]%s'. Continue?\", userInfo.DisplayName, email)) {\n\t\tfmt.Println(\"Operation cancelled\")\n\t\treturn nil\n\t}\n\n\thashPwd, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"encrypt password failed: %w\", err)\n\t}\n\n\tif err = userRepo.UpdatePass(ctx, userInfo.ID, string(hashPwd)); err != nil {\n\t\treturn fmt.Errorf(\"update password failed: %w\", err)\n\t}\n\n\tauthSvc.RemoveUserAllTokens(ctx, userInfo.ID)\n\n\tfmt.Printf(\"Password has been successfully updated for user: %s\\n\", email)\n\tfmt.Println(\"All login sessions have been cleared\")\n\n\treturn nil\n}\n\n// promptForPassword prompts for a password\nfunc promptForPassword() (string, error) {\n\tfor {\n\t\tinput, err := getPasswordInput(\"Please input new password (empty to generate random password): \")\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/cli/reset_password.go#L130-L166","documentation":"Fires in ResetPassword when userRepo.UpdatePass fails to persist the bcrypt hash for the user, i.e. the UPDATE against the user table errored (connection dropped, transaction failed, constraint/SQL error). The password was already validated and hashed; the failure is purely at the database write step.","triggerScenarios":"Thrown at internal/cli/reset_password.go:148 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped error from userRepo.UpdatePass for the underlying cause (connection lost, constraint violation, user deleted concurrently)","Verify database connectivity and that the DB is writable (not read-only, no active lock/maintenance)","Confirm the user still exists (it may have been deleted between lookup and update) and retry the command","Check application logs and the database error around the same timestamp for more detail"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}