{"record":{"id":"8e08347616619129","repo":"zincsearch/zincsearch","slug":"invalid-argument","errorCode":"invalid_argument","errorMessage":"user id is required","messagePattern":"user id is required","errorType":"validation","errorClass":"errors.Error","httpStatus":null,"severity":"error","filePath":"pkg/auth/getuser.go","lineNumber":26,"sourceCode":"*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n */\n\npackage auth\n\nimport (\n\t\"github.com/zincsearch/zincsearch/pkg/errors\"\n\t\"github.com/zincsearch/zincsearch/pkg/meta\"\n\t\"github.com/zincsearch/zincsearch/pkg/metadata\"\n)\n\nfunc GetUser(id string) (*meta.User, bool, error) {\n\tif id == \"\" {\n\t\treturn nil, false, errors.New(errors.ErrorTypeInvalidArgument, \"user id is required\")\n\t}\n\tuser, err := metadata.User.Get(id)\n\tif err != nil {\n\t\treturn nil, false, err\n\t}\n\treturn user, true, nil\n}\n\nfunc SetUser(id string, user meta.User) error {\n\treturn metadata.User.Set(id, user)\n}\n","sourceCodeStart":8,"sourceCodeEnd":38,"githubUrl":"https://github.com/zincsearch/zincsearch/blob/dd2f8afd6562d4d52c41b2c5d312280e684a25ba/pkg/auth/getuser.go#L8-L38","documentation":"GetUser(id) is the lookup function for users by their id. It validates that the id parameter is non-empty and returns an invalid_argument error when it is an empty string, preventing pointless storage lookups. The caller (e.g. CreateUser checking for name collisions) passes a value that ended up empty.","triggerScenarios":"Calling zinc.GetUser(\"\") directly, or CreateUser with an empty `_id`/name so that the internal uniqueness check calls GetUser with an empty id.","commonSituations":"Unmarshaling a user JSON document that lacks the id field; binding an HTTP request body where the id field is absent; concatenating/looking up users by a variable that was never populated.","solutions":["Ensure the user id is set and non-empty before calling GetUser or CreateUser","Validate request payloads server-side and reject user objects missing an id","When using CreateUser, pass a non-empty first argument (the id) since it is also used as the login name"],"exampleFix":"// before\nuser, exists, _ := zinc.GetUser(id)\n// after\nif id == \"\" {\n    return errors.New(\"user id must be provided\")\n}\nuser, exists, _ := zinc.GetUser(id)","handlingStrategy":"validation","validationCode":"if id == \"\" {\n    return fmt.Errorf(\"cannot look up user: id is empty\")\n}","typeGuard":"func hasUserID(u map[string]any) bool {\n    id, ok := u[\"_id\"].(string)\n    return ok && id != \"\"\n}","tryCatchPattern":"user, exists, err := zinc.GetUser(id)\nif err != nil {\n    if strings.Contains(err.Error(), \"user id is required\") {\n        return fmt.Errorf(\"caller bug: empty user id passed\")\n    }\n    return err\n}\nif !exists { /* handle not found */ }","preventionTips":["Always set _id when creating user documents","Validate HTTP payloads for the id field before calling auth APIs","Trim whitespace and reject empty ids at the handler boundary"],"tags":["validation","authentication","invalid-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"dd2f8afd6562d4d52c41b2c5d312280e684a25ba","analyzedAt":"2026-09-03T00:22:38.551Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}