{"record":{"id":"ed1a09d4d3d01fb2","repo":"hashie/hashie","slug":"expected-1-2-arguments-got-args-length","errorCode":null,"errorMessage":"Expected 1-2 arguments, got #{args.length}","messagePattern":"Expected 1-2 arguments, got #(.+?)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/hashie/rash.rb","lineNumber":67,"sourceCode":"        @regexes << key\n      when Range\n        @ranges << key\n      end\n      @hash[key] = value\n    end\n\n    #\n    # Return the first thing that matches the key.\n    #\n    def [](key)\n      all(key).first\n    end\n\n    #\n    # Raise (or yield) unless something matches the key.\n    #\n    def fetch(*args)\n      raise ArgumentError, \"Expected 1-2 arguments, got #{args.length}\" \\\n        unless (1..2).cover?(args.length)\n\n      key, default = args\n\n      all(key) do |value|\n        return value\n      end\n\n      if block_given?\n        yield key\n      elsif default\n        default\n      else\n        raise KeyError, \"key not found: #{key.inspect}\"\n      end\n    end\n\n    #","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/hashie/hashie/blob/fde8e03a0a19da626576415223e4b002fc373967/lib/hashie/rash.rb#L49-L85","documentation":"Hashie::Rash#fetch is defined as fetch(*args) and enforces its own arity: it raises ArgumentError unless exactly 1 or 2 positional arguments are passed (lib/hashie/rash.rb:66-68), mirroring Ruby's Hash#fetch(key[, default]). Because the signature is a splat, Ruby's native wrong-number-of-arguments check never fires; this explicit guard is the only arity enforcement. The failing call passed 0 arguments or 3 or more.","triggerScenarios":"Calling rash.fetch() with no arguments; calling rash.fetch(key, default, extra) with three or more arguments; forwarding a runtime-built array rash.fetch(*args) whose length is not 1 or 2; delegators (Forwardable, SimpleDelegator, method_missing proxies) that splat arguments through to fetch.","commonSituations":"Refactoring code from Hash#fetch into a Rash and leaving an options or third argument in place; wrapper libraries that proxy fetch with extra parameters; test helpers calling fetch with dynamically constructed argument lists.","solutions":["Call fetch with exactly 1 or 2 arguments: rash.fetch(key) or rash.fetch(key, default).","If forwarding variable args, destructure first: key, default = args.take(2); then rash.fetch(key, default).","For a computed fallback, pass a block instead of a third argument: rash.fetch(key) { compute_default } — the block runs only when nothing matches.","If a miss should not raise, use the nil-returning reader rash[key] instead of fetch."],"exampleFix":"# before\nargs = [query, default, options]\nvalue = rash.fetch(*args)  # ArgumentError: Expected 1-2 arguments, got 3\n\n# after\nquery, default = args.take(2)\nvalue = rash.fetch(query, default)","handlingStrategy":"validation","validationCode":"# validate dynamic args before calling Hashie::Rash#fetch\nfail ArgumentError, \"fetch needs 1-2 args, got #{args.length}\" unless (1..2).cover?(args.length)\nrash.fetch(*args)","typeGuard":"# Ruby arity predicate for Rash#fetch call sites\ndef rash_fetch_arity_ok?(*args) = (1..2).cover?(args.length)","tryCatchPattern":"begin\n  rash.fetch(*args)\nrescue ArgumentError => e\n  raise unless e.message.start_with?('Expected 1-2 arguments')\n\n  rash[args.first] # degrade to the nil-returning reader\nend","preventionTips":["Never splat an unvalidated array into fetch; destructure to exactly key and optional default first.","Keep dynamic-arity wrappers and extra options away from fetch — its contract is fixed at 1-2 arguments.","Unit-test delegating code with 0- and 3-argument edge cases."],"tags":["ruby","hashie","rash","fetch","argumenterror","arity"],"backgroundTag":"wrong-number-of-arguments","analyzedSha":"fde8e03a0a19da626576415223e4b002fc373967","analyzedAt":"2026-08-23T14:54:52.149Z","schemaVersion":2},"datasetVersion":"2026-08-23T16:17:53.355Z"}