{"record":{"id":"2cb87322f2105a99","repo":"SigNoz/signoz","slug":"errcodeuserroleinvalidinput","errorCode":"ErrCodeUserRoleInvalidInput","errorMessage":"userId is required","messagePattern":"userId is required","errorType":"validation","errorClass":"errors SigNozError","httpStatus":400,"severity":"error","filePath":"pkg/types/authtypes/user_role.go","lineNumber":63,"sourceCode":"type DeprecatedPostableUserRole struct {\n\tID valuer.UUID `json:\"id\" required:\"true\"`\n}\n\ntype PostableUserRole struct {\n\tUserID valuer.UUID `json:\"userId\" required:\"true\"`\n\tRoleID valuer.UUID `json:\"roleId\" required:\"true\"`\n}\n\nfunc (p *PostableUserRole) UnmarshalJSON(data []byte) error {\n\ttype Alias PostableUserRole\n\n\tvar temp Alias\n\tif err := json.Unmarshal(data, &temp); err != nil {\n\t\treturn err\n\t}\n\n\tif temp.UserID.IsZero() {\n\t\treturn errors.New(errors.TypeInvalidInput, ErrCodeUserRoleInvalidInput, \"userId is required\")\n\t}\n\n\tif temp.RoleID.IsZero() {\n\t\treturn errors.New(errors.TypeInvalidInput, ErrCodeUserRoleInvalidInput, \"roleId is required\")\n\t}\n\n\t*p = PostableUserRole(temp)\n\treturn nil\n}\n\nfunc (p *PostableUser) UnmarshalJSON(data []byte) error {\n\ttype Alias PostableUser\n\n\tvar temp Alias\n\tif err := json.Unmarshal(data, &temp); err != nil {\n\t\treturn err\n\t}\n","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/types/authtypes/user_role.go#L45-L81","documentation":"PostableUserRole.UnmarshalJSON requires a non-zero userId. The alias struct decodes UserID as a typed ID; a zero value (missing, empty, or all-zero UUID) fails validation before roleId is checked.","triggerScenarios":"POSTing a user-role assignment JSON without userId, with an empty string, or with an all-zero UUID; unmarshalling request bodies in role-assignment APIs.","commonSituations":"Clients constructing payloads programmatically omitting optional-looking fields; frontend forms not validating the user selector; test fixtures copied without user IDs.","solutions":["Include a valid non-zero userId in the request body","Check the field name casing matches the JSON tag (userId) exactly","Log the decoded payload before send to confirm the field is serialized","Validate required fields client-side before submitting"],"exampleFix":"// before\n{\"roleId\":\"01HQ...\"}\n// after\n{\"userId\":\"01HQ...user\",\"roleId\":\"01HQ...role\"}\n","handlingStrategy":"validation","validationCode":"if req.UserID == \"\" || isZeroUUID(req.UserID) { return errors.New(\"userId required\") }","typeGuard":"func hasUserID(p map[string]any) bool { id, ok := p[\"userId\"].(string); return ok && id != \"\" && id != \"00000000-0000-0000-0000-000000000000\" }","tryCatchPattern":null,"preventionTips":["Validate required IDs before POST","Use typed client SDKs so missing fields are compile-time visible"],"tags":["json","validation","user-roles","go"],"backgroundTag":"required-field-missing","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}