instructure/canvas-lms · error
unknown item type
Error message
unknown item type
What it means
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.
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.
Example fix
// before helper.visible_item_ids_for_users(item.type_name, user_ids) // after type = item.type_name.to_sym raise ArgumentError unless Courses::ItemVisibilityHelper::ITEM_TYPES.include?(type) helper.visible_item_ids_for_users(type, user_ids)
Defensive patterns
Strategy: validation
Validate before calling
raise 'bad type' unless Courses::ItemVisibilityHelper::ITEM_TYPES.include?(type.to_sym)
Type guard
def known_item_type?(type) Courses::ItemVisibilityHelper::ITEM_TYPES.include?(type.to_sym) end
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- [Accessibility::CategoryBreakdownService] dropping unknown…
- # is invalid
- Course pace is deleted
- Course pace is not deleted
- Course required
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/aa267c2eaf9b240b.
Report an issue: GitHub.
Appendix: source
Thrown at app/models/courses/item_visibility_helper.rb:27
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
module Courses
module ItemVisibilityHelper
ITEM_TYPES = %i[assignment discussion page quiz].freeze
def visible_item_ids_for_users(item_type, user_ids)
# return all the item ids that are visible to _any_ of the users
raise "unknown item type" unless ITEM_TYPES.include?(item_type)
cache_visibilities_for_users(item_type, user_ids)
user_ids.flat_map { |user_id| @cached_visibilities.dig(item_type, user_id) }.uniq
end
def cache_item_visibilities_for_user_ids(user_ids)
ITEM_TYPES.each do |item_type|
cache_visibilities_for_users(item_type, user_ids)
end
end
def clear_cached_item_visibilities
@cached_visibilities&.clear
end
private
def cache_visibilities_for_users(item_type, user_ids)View on GitHub (pinned to 1c9f0bb801)