{"record":{"id":"c8985f95593ca859","repo":"instructure/canvas-lms","slug":"could-not-set-delivery-method-from-path-type","errorCode":null,"errorMessage":"Could not set delivery_method from #{path_type}","messagePattern":"Could not set delivery_method from #(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"app/models/message.rb","lineNumber":762,"sourceCode":"       (Notification.types_to_send_in_push.exclude?(notification_name) || !check_acct.enable_push_notifications?)\n      return skip_and_cancel\n    end\n\n    InstStatsd::Statsd.distributed_increment(\"message.deliver.#{path_type}.#{notification_name}\",\n                                             short_stat: \"message.deliver\",\n                                             tags: { path_type:, notification_name: })\n\n    global_account_id = Shard.global_id_for(root_account_id, shard)\n    InstStatsd::Statsd.increment(\"message.deliver.#{path_type}.#{global_account_id}\",\n                                 short_stat: \"message.deliver_per_account\",\n                                 tags: { path_type: }.merge(Utils::InstStatsdUtils::Tags.tags_for(shard)))\n\n    if check_acct.feature_enabled?(:notification_service)\n      enqueue_to_sqs\n    else\n      delivery_method = :\"deliver_via_#{path_type}\"\n      if !delivery_method || !respond_to?(delivery_method, true)\n        logger.warn(\"Could not set delivery_method from #{path_type}\")\n        return nil\n      end\n      send(delivery_method)\n    end\n  end\n\n  def skip_and_cancel\n    InstStatsd::Statsd.distributed_increment(\"message.skip.#{path_type}.#{notification_name}\",\n                                             short_stat: \"message.skip\",\n                                             tags: { path_type:, notification_name: })\n    cancel\n  end\n\n  # Public: Enqueues a message to the notification_service's sqs queue\n  #\n  # Returns nothing\n  def enqueue_to_sqs\n    targets = notification_targets","sourceCodeStart":744,"sourceCodeEnd":780,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/models/message.rb#L744-L780","documentation":"Message#deliver in Canvas resolves the delivery path by building a dynamic method name `deliver_via_#{path_type}` and checking it exists via respond_to?. If the message's path_type does not map to a known private delivery method (e.g. deliver_via_email, deliver_via_sms, deliver_via_twitter), it logs this warning and returns nil instead of delivering. It is a guard against unknown or removed notification policy delivery channel types.","triggerScenarios":"A Message is delivered whose path_type (derived from the NotificationPolicy/communication channel type) is not one of the supported types with a corresponding deliver_via_* method — e.g. a stale/unknown channel type string, a typo'd path_type, or a delivery method removed in a refactor while old path_types remain in the DB. Note the code also checks `!delivery_method` which can only be truthy if path_type is nil.","commonSituations":"Legacy or orphaned communication channels / notification policies in the database referencing channel types no longer supported; plugins defining custom channels being disabled so deliver_via_* methods disappear; nil path_type on a message built without a proper path.","solutions":["Inspect the message's path_type (`Message.find(id).path_type`) and confirm it matches a supported channel type with a deliver_via_* method in app/models/message.rb","Clean up stale NotificationPolicy/CommunicationChannel records whose channel types no longer exist","If a plugin or shard provides custom channels, ensure the code defining deliver_via_<type> is loaded in the delivering process","Add a mapping/allowlist for valid path_types before calling deliver so bad data is rejected upstream"],"exampleFix":"# before\ndelivery_method = :\"deliver_via_#{path_type}\"\nif !delivery_method || !respond_to?(delivery_method, true)\n  logger.warn(\"Could not set delivery_method from #{path_type}\")\n  return nil\nend\n\n# after: validate path_type up front\nSUPPORTED_PATH_TYPES = %w[email sms push twitter].freeze\nunless SUPPORTED_PATH_TYPES.include?(path_type.to_s)\n  logger.warn(\"Could not set delivery_method from #{path_type}\")\n  return nil\nend\nsend(\"deliver_via_#{path_type}\")","handlingStrategy":"validation","validationCode":"unless Message.respond_to?(\"deliver_via_#{path_type}\", true)\n  Rails.logger.warn(\"Unknown path_type #{path_type.inspect}; skipping delivery\")\nend","typeGuard":"def deliverable_path_type?(msg)\n  pt = msg.path_type.to_s\n  !pt.empty? && msg.respond_to?(\"deliver_via_#{pt}\", true)\nend","tryCatchPattern":null,"preventionTips":["Validate path_type against a supported-channel allowlist before creating messages","Clean up stale communication channels / notification policies regularly","Keep deliver_via_* methods and channel types in one registry so they can't drift apart"],"tags":["ruby","rails","notifications","dynamic-dispatch"],"backgroundTag":"unsupported-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"}