{"record":{"id":"b19090b2153997a8","repo":"m1k1o/neko","slug":"errmemberalreadyexists","errorCode":"ErrMemberAlreadyExists","errorMessage":"member already exists","messagePattern":"member already exists","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/pkg/types/member.go","lineNumber":6,"sourceCode":"package types\n\nimport \"errors\"\n\nvar (\n\tErrMemberAlreadyExists   = errors.New(\"member already exists\")\n\tErrMemberDoesNotExist    = errors.New(\"member does not exist\")\n\tErrMemberInvalidPassword = errors.New(\"invalid password\")\n)\n\ntype MemberProfile struct {\n\tName string `json:\"name\"`\n\n\t// permissions\n\tIsAdmin               bool `json:\"is_admin\"                 mapstructure:\"is_admin\"`\n\tCanLogin              bool `json:\"can_login\"                mapstructure:\"can_login\"`\n\tCanConnect            bool `json:\"can_connect\"              mapstructure:\"can_connect\"`\n\tCanWatch              bool `json:\"can_watch\"                mapstructure:\"can_watch\"`\n\tCanHost               bool `json:\"can_host\"                 mapstructure:\"can_host\"`\n\tCanShareMedia         bool `json:\"can_share_media\"          mapstructure:\"can_share_media\"`\n\tCanAccessClipboard    bool `json:\"can_access_clipboard\"     mapstructure:\"can_access_clipboard\"`\n\tSendsInactiveCursor   bool `json:\"sends_inactive_cursor\"    mapstructure:\"sends_inactive_cursor\"`\n\tCanSeeInactiveCursors bool `json:\"can_see_inactive_cursors\" mapstructure:\"can_see_inactive_cursors\"`\n","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/m1k1o/neko/blob/b0f01cedea68893e85a3fd852c0521238c285695/server/pkg/types/member.go#L1-L24","documentation":"ErrMemberAlreadyExists is a sentinel error returned when inserting a member whose username/ID already exists in the member store (membersCreate -> Insert). The members repository enforces uniqueness, so creating a duplicate user is rejected with this error.","triggerScenarios":"POST /members (membersCreate) with a username that already exists; concurrent creation of the same user; importing/restoring members into a non-empty store without clearing duplicates.","commonSituations":"Admin re-running a user-creation script; registering a username someone else took; data import colliding with existing users; retrying a request that actually succeeded the first time.","solutions":["Pick a different, unused username","Check existence first (list/get member) and update the existing member instead of creating","Handle errors.Is(err, types.ErrMemberAlreadyExists) in the API layer and return HTTP 409","Deduplicate your import data against the current member list before inserting"],"exampleFix":"// before\nerr := members.Insert(username, password, profile)\nif err != nil { return err }\n// after\nerr := members.Insert(username, password, profile)\nif errors.Is(err, types.ErrMemberAlreadyExists) {\n  return http.StatusConflict, \"user already exists\"\n}\nif err != nil { return err }","handlingStrategy":"validation","validationCode":"_, err := members.Get(username)\nif err == nil {\n  // member exists; update instead of insert\n}","typeGuard":"func memberExists(m types.Members, username string) bool {\n  _, err := m.Get(username)\n  return err == nil\n}","tryCatchPattern":"err := members.Insert(username, password, profile)\nif errors.Is(err, types.ErrMemberAlreadyExists) {\n  // return 409 or update the existing member\n}","preventionTips":["Uniqueness-check the username in the UI before submit","Use errors.Is with the sentinel error, not string comparison","Handle duplicates on import by upserting","Return HTTP 409 from the API on this sentinel error"],"tags":["members","users","duplicate"],"backgroundTag":"resource-already-exists","analyzedSha":"b0f01cedea68893e85a3fd852c0521238c285695","analyzedAt":"2026-09-01T10:35:56.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}