instructure/canvas-lms · error · ArgumentError

Missing required parameter: #

Error message

Missing required parameter: #{param_name}

What it means

Lti::Pns::LtiAssetProcessorContributionNoticeBuilder#validate_params! iterates REQUIRED_PARAMS and raises ArgumentError for the first param_name whose value is falsy (nil/false) in the params hash passed to the builder's initialize.

Solutions

  1. Inspect REQUIRED_PARAMS in the builder and supply every listed key before constructing
  2. Add a pre-build validation that checks each REQUIRED_PARAMS key is present in your params hash
  3. Rescue ArgumentError at the call site and log which parameter was missing

Example fix

// before
Lti::Pns::LtiAssetProcessorContributionNoticeBuilder.new({ assets: [...] })
// after
params = { assets: [...], context: ctx, ... }
missing = Lti::Pns::LtiAssetProcessorContributionNoticeBuilder::REQUIRED_PARAMS.reject { |p| params[p] }
raise "missing #{missing}" unless missing.empty?
Lti::Pns::LtiAssetProcessorContributionNoticeBuilder.new(params)
Defensive patterns

Strategy: validation

Validate before calling

missing = Lti::Pns::LtiAssetProcessorContributionNoticeBuilder::REQUIRED_PARAMS.reject { |k| params[k] }
raise "missing: #{missing}" unless missing.empty?

Try / catch

begin
  Builder.new(params)
rescue ArgumentError => e
  Rails.logger.error("PNS builder: #{e.message}")
end

Prevention

When it happens

Trigger: Instantiating the notice builder without one of the REQUIRED_PARAMS keys present (or set to nil/false) in the params hash.

Common situations: Callers (e.g. observer/asset processor notification pipelines) omitting fields after a refactor; nil values propagated from upstream queries; hash built dynamically with missing keys.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15). Data as JSON: /api/errors/08424ccbb7ce2b48. Report an issue: GitHub.

Appendix: source

Thrown at app/models/lti/pns/lti_asset_processor_contribution_notice_builder.rb:54

      HIDDEN = "Hidden"

      VALID_CONTRIBUTION_STATUSES = [
        DRAFT,
        SUBMITTED,
        DELETED,
        HIDDEN
      ].freeze

      def initialize(params)
        validate_params!(params)
        @params = params
        ensure_lti_ids
        super()
      end

      def validate_params!(params)
        REQUIRED_PARAMS.each do |param_name|
          raise ArgumentError, "Missing required parameter: #{param_name}" unless params[param_name]
        end
        params[:assets].each do |asset|
          REQUIRED_ASSETS_PARAMS.each do |asset_param_name|
            raise ArgumentError, "Missing required asset parameter #{asset_param_name}" unless asset[asset_param_name]
          end
        end
        if params[:assets].any? && params[:asset_report_service_url].blank?
          raise ArgumentError, "Missing required parameter: asset_report_service_url when assets are present"
        end
        unless VALID_CONTRIBUTION_STATUSES.include?(params[:contribution_status])
          raise ArgumentError, "Invalid contribution_status: #{params[:contribution_status]}. Must be one of: #{VALID_CONTRIBUTION_STATUSES.join(", ")}"
        end
      end

      def notice_type
        NoticeTypes::ASSET_PROCESSOR_CONTRIBUTION
      end

View on GitHub (pinned to 1c9f0bb801)