{"record":{"id":"11f41b3d46ae8169","repo":"juanfont/headscale","slug":"updating-user-w","errorCode":null,"errorMessage":"updating user: %w","messagePattern":"updating user: %w","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"hscontrol/state/state.go","lineNumber":432,"sourceCode":"}\n\n// UpdateUser modifies an existing user using the provided update function within a transaction.\n// Returns the updated user, change set, and any error.\nfunc (s *State) UpdateUser(userID types.UserID, updateFn func(*types.User) error) (*types.User, change.Change, error) {\n\tuser, err := hsdb.Write(s.db.DB, func(tx *gorm.DB) (*types.User, error) {\n\t\tuser, err := hsdb.GetUserByID(tx, userID)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tif err := updateFn(user); err != nil { //nolint:noinlineerr\n\t\t\treturn nil, err\n\t\t}\n\n\t\t// Use Updates() to only update modified fields, preserving unchanged values.\n\t\terr = tx.Updates(user).Error\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"updating user: %w\", err)\n\t\t}\n\n\t\treturn user, nil\n\t})\n\tif err != nil {\n\t\treturn nil, change.Change{}, err\n\t}\n\n\t// Check if policy manager needs updating\n\tc, err := s.updatePolicyManagerUsers()\n\tif err != nil {\n\t\treturn user, change.Change{}, fmt.Errorf(\"updating policy manager after user update: %w\", err)\n\t}\n\n\t// TODO(kradalby): We might want to update nodestore with the user data\n\n\treturn user, c, nil\n}","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/hscontrol/state/state.go#L414-L450","documentation":"Error \"updating user: %w\" thrown in juanfont/headscale.","triggerScenarios":"Thrown at hscontrol/state/state.go:432 when the library encounters an invalid state.","commonSituations":"Updating the user record failed. Verify the user exists and new field values are valid.","solutions":["Inspect the wrapped error for the underlying cause and correct the failing condition (updating user); retry the operation after fixing the input, configuration, or environment."],"exampleFix":"Inspect the wrapped error for the underlying cause and correct the failing condition (updating user); retry the operation after fixing the input, configuration, or environment.","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}