{"record":{"id":"0e3d46cabd175b7f","repo":"instructure/canvas-lms","slug":"need-more-arguments","errorCode":null,"errorMessage":"Need more arguments","messagePattern":"Need more arguments","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"gems/canvas_crummy/lib/canvas_crummy/controller_methods.rb","lineNumber":39,"sourceCode":"  module ControllerMethods\n    module ClassMethods\n      # Add a crumb to the crumbs array.\n      #\n      #   add_crumb(\"Home\", \"/\")\n      #   add_crumb(\"Business\") { |instance| instance.business_path }\n      #\n      # Works like a before_filter so +:only+ and +except+ both work.\n      def add_crumb(name, *args)\n        options = args.extract_options!\n        url = args.first\n        # I wanted this next line to look more like:\n        # html_options = options.pluck { |k,v| %w{class id}.include? k.to_s  }\n        # but couldn't figure out how\n        html_options = (klass = options.delete(:class)) ? { class: klass } : {}\n        if (id = options.delete(:id))\n          html_options[:id] = id\n        end\n        raise ArgumentError, \"Need more arguments\" unless name || block_given?\n        raise ArgumentError, \"Cannot pass url and use block\" if url && block_given?\n\n        before_action(options) do |instance|\n          url_value = url\n          url_value = yield instance if block_given?\n          url_value = instance.send url_value if url_value.is_a? Symbol\n          name_value = name\n          name_value = instance.instance_eval(&name_value) if name_value.is_a? Proc\n          name_value = instance.instance_variable_get(:\"@#{name_value}\") if name_value.is_a? Symbol\n          record = instance.instance_variable_get(:\"@#{name_value}\") unless url_value || block_given?\n          if record\n            name_value, url_value = record.to_s, instance.url_for(record)\n          end\n\n          # FIXME: url_value = instance.url_for(name_value) if name_value.respond_to?(\"to_param\") && url_value.nil?\n          # FIXME: Add ||= for the name_value, url_value above\n          instance.add_crumb(name_value, url_value, html_options)\n        end","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/gems/canvas_crummy/lib/canvas_crummy/controller_methods.rb#L21-L57","documentation":"canvas_crummy's add_crumb (controller method) builds a navigation crumb from a name and/or url/block. At least one of a name argument or a block is required — without either there's nothing to render — so it raises ArgumentError. (A companion check forbids passing both a url and a block.)","triggerScenarios":"Calling add_crumb() with no arguments and no block, e.g. add_crumb in a controller; calling add_crumb(options...) where the name positional is nil at runtime and no block is attached; dynamic name via block that was accidentally removed.","commonSituations":"Refactoring breadcrumbs to compute names lazily but dropping the block; passing only html-style options (:class/:id) and forgetting the name; conditional code where name falls through nil.","solutions":["Pass a name: add_crumb('Courses', courses_path)","Use a block for lazy names: add_crumb { |c| c.name }","Ensure a dynamically computed name variable is non-nil, or default it","If a URL is passed with dynamic naming, pass name explicitly rather than relying on a block"],"exampleFix":"// before\nadd_crumb(class: 'strong')\n// after\nadd_crumb('Dashboard', class: 'strong')","handlingStrategy":"validation","validationCode":"raise 'add_crumb needs name or block' if name.nil? && !block_given?","typeGuard":null,"tryCatchPattern":"begin\n  add_crumb(name, url)\nrescue ArgumentError => e\n  Rails.logger.warn(\"bad crumb: #{e.message}\")\nend","preventionTips":["Always pass a name string (or block) to add_crumb","Never pass both url and block — pick one","Guard dynamically computed crumb names against nil"],"tags":["ruby","breadcrumbs","argument-error"],"backgroundTag":"missing-required-argument","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"}