{"record":{"id":"aa267c2eaf9b240b","repo":"instructure/canvas-lms","slug":"unknown-item-type","errorCode":null,"errorMessage":"unknown item type","messagePattern":"unknown item type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/models/courses/item_visibility_helper.rb","lineNumber":27,"sourceCode":"# 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#\n\nmodule Courses\n  module ItemVisibilityHelper\n    ITEM_TYPES = %i[assignment discussion page quiz].freeze\n\n    def visible_item_ids_for_users(item_type, user_ids)\n      # return all the item ids that are visible to _any_ of the users\n      raise \"unknown item type\" unless ITEM_TYPES.include?(item_type)\n\n      cache_visibilities_for_users(item_type, user_ids)\n      user_ids.flat_map { |user_id| @cached_visibilities.dig(item_type, user_id) }.uniq\n    end\n\n    def cache_item_visibilities_for_user_ids(user_ids)\n      ITEM_TYPES.each do |item_type|\n        cache_visibilities_for_users(item_type, user_ids)\n      end\n    end\n\n    def clear_cached_item_visibilities\n      @cached_visibilities&.clear\n    end\n\n    private\n\n    def cache_visibilities_for_users(item_type, user_ids)","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/models/courses/item_visibility_helper.rb#L9-L45","documentation":"ItemVisibilityHelper#visible_item_ids_for_users only accepts item types in ITEM_TYPES (:assignment, :discussion, :page, :quiz). Any other symbol raises 'unknown item type' before computing per-user visibility.","triggerScenarios":"Calling visible_item_ids_for_users(:announcement, user_ids), :module_item, :file, or any symbol not in the frozen ITEM_TYPES list; passing a string 'quiz' instead of the :quiz symbol.","commonSituations":"Extending visibility reporting to a new content type without adding it to ITEM_TYPES; dynamic code deriving the item type from a DB string and not symbolizing/validating it; typos like :assingment.","solutions":["Use one of :assignment, :discussion, :page, :quiz.","Convert DB strings to symbols with .to_sym and validate membership in ITEM_TYPES first.","Add the new type to ITEM_TYPES (and the corresponding visibility scoping code) if support is genuinely needed."],"exampleFix":"// before\nhelper.visible_item_ids_for_users(item.type_name, user_ids)\n\n// after\ntype = item.type_name.to_sym\nraise ArgumentError unless Courses::ItemVisibilityHelper::ITEM_TYPES.include?(type)\nhelper.visible_item_ids_for_users(type, user_ids)","handlingStrategy":"validation","validationCode":"raise 'bad type' unless Courses::ItemVisibilityHelper::ITEM_TYPES.include?(type.to_sym)","typeGuard":"def known_item_type?(type)\n  Courses::ItemVisibilityHelper::ITEM_TYPES.include?(type.to_sym)\nend","tryCatchPattern":null,"preventionTips":["Keep an exhaustive case/when over ITEM_TYPES at call sites","Symbolize and validate DB-sourced type strings before use","Extend ITEM_TYPES and scoping code together in the same change"],"tags":["ruby-on-rails","visibility","enum"],"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"}