{"record":{"id":"22238ea681dafbda","repo":"instructure/canvas-lms","slug":"invalid-enrollment-type-e","errorCode":null,"errorMessage":"Invalid enrollment type: #{e}","messagePattern":"Invalid enrollment type: #(.+?)","errorType":"exception","errorClass":"RequestError","httpStatus":400,"severity":"error","filePath":"lib/user_search.rb","lineNumber":26,"sourceCode":"# Canvas is free software: you can redistribute it and/or modify it under\n# the terms of the GNU Affero General Public License as published by the Free\n# Software Foundation, version 3 of the License.\n#\n# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY\n# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR\n# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more\n# details.\n#\n# You should have received a copy of the GNU Affero General Public License along\n# with this program. If not, see <http://www.gnu.org/licenses/>.\n\nmodule UserSearch\n  class << self\n    def validate_enrollment_types(enrollment_types)\n      enrollment_types.map do |e|\n        ce = e.camelize\n        ce += \"Enrollment\" unless ce.end_with?(\"Enrollment\")\n        raise RequestError.new(\"Invalid enrollment type: #{e}\", 400) unless Enrollment.readable_types.key?(ce)\n\n        ce\n      end\n    end\n\n    def for_user_in_context(search_term, context, searcher, session = nil, options = {})\n      search_term = search_term.to_s\n      return User.none if search_term.strip.empty?\n\n      SearchTermHelper.validate_search_term(search_term)\n\n      @is_id = search_term =~ Api::ID_REGEX && Api::MAX_ID_RANGE.cover?(search_term.to_i)\n      @include_login       = context.grants_right?(searcher, session, :view_user_logins)\n      @include_email       = context.grants_right?(searcher, session, :read_email_addresses)\n      @include_sis         = context.grants_any_right?(searcher, session, :read_sis, :manage_sis)\n      @include_integration = @include_sis\n      @include_deleted_users = options[:include_deleted_users]\n","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/user_search.rb#L8-L44","documentation":"UserSearch.validate_enrollment_types in lib/user_search.rb:26 raises RequestError (400) when a camelized enrollment type is not a key in Enrollment.readable_types. It guarantees the enrollment_types filter passed to user queries only contains enrollment types the searcher is permitted to read.","triggerScenarios":"Passing enrollment_types like ['StudentEnrollment'] misspelled, or types such as 'FakeEnrollment', or values not readable in the context into UserSearch / roles_scope.","commonSituations":"API params enrollment_type[] with invalid values hitting user index endpoints; plugins or custom code referencing removed enrollment types; typos like 'TaEnrollment' vs 'TaEnrolment' in client code.","solutions":["Use valid enrollment type strings: TeacherEnrollment, StudentEnrollment, TaEnrollment, DesignerEnrollment, ObserverEnrollment","Validate/whitelist enrollment_type params in the controller before calling UserSearch","Check Enrollment.readable_types in a console to list valid types for the context","Rescue RequestError to convert it into a 400 response with a clear message"],"exampleFix":"// before\nUserSearch.validate_enrollment_types(['Student'])\n// after\nUserSearch.validate_enrollment_types(['StudentEnrollment']) # or 'student', which camelizes correctly","handlingStrategy":"validation","validationCode":"invalid = enrollment_types.reject { |e| Enrollment.readable_types.key?(e.camelize.sub(/Enrollment\\z/, '') == e.camelize ? e.camelize : e.camelize + 'Enrollment') }","typeGuard":null,"tryCatchPattern":"begin\n  UserSearch.validate_enrollment_types(params[:enrollment_type])\nrescue RequestError => e\n  render json: {error: e.message}, status: 400\nend","preventionTips":["Always pass fully-camelized or correctly-cased enrollment type strings","Check Enrollment.readable_types when introducing new filters","Reject unknown enrollment_type[] params in controllers"],"tags":["ruby","enrollment","validation","http-400"],"backgroundTag":"invalid-enum-value","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}