ruby-grape / ruby-grape/grape

Error in AsValidator when using nested parameters

Open
#2,044 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug?
Dominant language
Ruby
Stars
10k
Forks
1.2k
Avg merge
14h 38m
Merged PRs (30d)
92

Description

Possible fix is to rescue all errors and re-raise as a Grape::Exceptions::Validation.

module Grape
  module Validations
    class AsValidator < Base
      def initialize(attrs, options, required, scope, opts = {})
        @renamed_options = options
        super
      end

      def validate_param!(attr_name, params)
        params[@renamed_options] = params[attr_name]
      rescue StandardError => _e
        raise Grape::Exceptions::Validation.new(
          params: [@scope.full_name(attr_name)],
          message: message(:invalid_format),
        )
      end
    end
  end
end

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at Grape::Validations::AsValidator#validate_param! and inspect how nested parameters reach the assignment using @renamed_options. Confirm that failures there become Grape::Exceptions::Validation with the scoped attribute and invalid-format message, rather than an unrelated raw error.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.