{"record":{"id":"f2eb58470d33f673","repo":"ruby-grape/grape","slug":"with-with-class-expected-symbol-string-or-pr","errorCode":null,"errorMessage":"with: #{with.class}, expected Symbol, String or Proc","messagePattern":"with: #(.+?), expected Symbol, String or Proc","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/grape/dsl/request_response.rb","lineNumber":154,"sourceCode":"      def represent(model_class, with:)\n        raise Grape::Exceptions::InvalidWithOptionForRepresent.new unless with.is_a?(Class)\n\n        inheritable_setting.add_representation(model_class, with)\n      end\n\n      private\n\n      def extract_handler(args, with:, block:)\n        raise ArgumentError, 'both :with option and block cannot be passed' if block && with\n\n        return args.pop if args.last.is_a?(Proc)\n        return block if block\n        return unless with\n\n        case with\n        when Proc, Symbol then with\n        when String then with.to_sym\n        else raise ArgumentError, \"with: #{with.class}, expected Symbol, String or Proc\"\n        end\n      end\n    end\n  end\nend\n","sourceCodeStart":136,"sourceCodeEnd":160,"githubUrl":"https://github.com/ruby-grape/grape/blob/22d7975629846a3c0c7bd2b34e140a7a1b4af8f6/lib/grape/dsl/request_response.rb#L136-L160","documentation":"The `with:` option of `rescue_from` must be a handler reference Grape can invoke: a Proc, a Symbol naming an endpoint method, or a String that is converted with to_sym. Any other class (Integer, Hash, Class, nil-replacement objects) raises ArgumentError with the offending class name, since Grape cannot dispatch it when an exception is raised at runtime.","triggerScenarios":"`rescue_from ArgumentError, with: 42` or `with: { message: 'err' }`. `with: SomeModule` (passing a class instead of a Proc). `with: 'render_error '`-style values are fine as Strings, but a frozen numeric/boolean option raises.","commonSituations":"Passing configuration hashes or objects intended for the handler body instead of a handler reference. Typos like `with: :render_errorrs`. Dynamically computing the handler and accidentally passing nil-replacement or non-callable values.","solutions":["Pass a Symbol naming a defined helper/instance method: `with: :render_error`.","Pass a Proc/lambda: `with: ->(e) { error!(e.message, 500) }` (String method names are also accepted and to_sym-ed).","If you need extra data, close over it in the Proc or define a dedicated method instead of passing a Hash."],"exampleFix":"# before\nrescue_from ArgumentError, with: { code: 400, msg: 'bad' } # raises with: Hash\n\n# after\nrescue_from ArgumentError, with: ->(e) { error!(e.message, 400) }\n\n# or\nrescue_from ArgumentError, with: :render_error\ndef render_error(e); error!({ code: 400, msg: e.message }, 400); end","handlingStrategy":"type-guard","validationCode":"def valid_with_option?(with) = with.is_a?(Proc) || with.is_a?(Symbol) || with.is_a?(String)\n\nraise ArgumentError, 'with: must be Symbol, String, or Proc' unless valid_with_option?(my_with)","typeGuard":"def handler_ref?(value) = value.is_a?(Proc) || value.is_a?(Symbol) || value.is_a?(String)","tryCatchPattern":null,"preventionTips":["Pass `with: :method_name` or `with: ->(e) {}` only - never data structures.","Freeze a set of known handler names and check dynamic values against it.","Boot specs catch bad `with:` values at definition time."],"tags":["grape","rescue-from","with-option","handler","argument-type"],"backgroundTag":"invalid-handler-reference","analyzedSha":"22d7975629846a3c0c7bd2b34e140a7a1b4af8f6","analyzedAt":"2026-08-21T17:03:54.627Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}