{"record":{"id":"7b087e32b4cfe1f5","repo":"ruby/ruby","slug":"mem-size-must-be-a-integer","errorCode":null,"errorMessage":"mem_size must be a Integer","messagePattern":"mem_size must be a Integer","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"yjit.rb","lineNumber":57,"sourceCode":"  #\n  # * `stats`:\n  #     * `false`: Don't enable stats.\n  #     * `true`: Enable stats. Print stats at exit.\n  #     * `:quiet`: Enable stats. Do not print stats at exit.\n  # * `log`:\n  #     * `false`: Don't enable the log.\n  #     * `true`: Enable the log. Print log at exit.\n  #     * `:quiet`: Enable the log. Do not print log at exit.\n  def self.enable(stats: false, log: false, mem_size: nil, call_threshold: nil)\n    return false if enabled?\n\n    if Primitive.cexpr! 'RBOOL(rb_zjit_enabled_p)'\n      warn(\"Only one JIT can be enabled at the same time.\")\n      return false\n    end\n\n    if mem_size\n      raise ArgumentError, \"mem_size must be a Integer\" unless mem_size.is_a?(Integer)\n      raise ArgumentError, \"mem_size must be between 1 and 2048 MB\" unless (1..2048).include?(mem_size)\n    end\n\n    if call_threshold\n      raise ArgumentError, \"call_threshold must be a Integer\" unless call_threshold.is_a?(Integer)\n      raise ArgumentError, \"call_threshold must be a positive integer\" unless call_threshold.positive?\n    end\n\n    at_exit { print_and_dump_stats } if stats\n    Primitive.rb_yjit_enable(stats, stats != :quiet, log, log != :quiet, mem_size, call_threshold)\n  end\n\n  # If --yjit-trace-exits is enabled parse the hashes from\n  # Primitive.rb_yjit_get_exit_locations into a format readable\n  # by Stackprof. This will allow us to find the exact location of a\n  # side exit in YJIT based on the instruction that is exiting.\n  def self.exit_locations # :nodoc:\n    return unless trace_exit_locations_enabled?","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/ruby/ruby/blob/0e5b888e1c355f3f728f2659f085820937dada48/yjit.rb#L39-L75","documentation":"RubyVM::YJIT.enable validates the mem_size keyword (executable code area size, in MB) and requires a true Integer. Strings ('128') and Floats — including whole-valued ones like 64.0 — fail mem_size.is_a?(Integer) and raise ArgumentError. The same value must then be within 1..2048, but that is a separate check.","triggerScenarios":"RubyVM::YJIT.enable(mem_size: '128') with a String from ENV or YAML config; mem_size: 64.0 produced by a Float computation or JSON number parsing; any truthy non-Integer (nil is allowed and skips validation).","commonSituations":"Reading mem_size from ENV variables or YAML without to_i; arithmetic that produced Floats (64.0/1); JSON configs whose numbers parse as Float.","solutions":["Coerce at the boundary: mem_size: value&.to_i for trusted config, or Integer(value) for strict parsing","Pass an Integer literal within the documented 1..2048 range","Validate config types once at load time (ENV schema, dry-validation) so YJIT.enable never sees strings"],"exampleFix":"# before\nRubyVM::YJIT.enable(mem_size: ENV['YJIT_MEM_SIZE'])  # String from ENV -> ArgumentError\n\n# after\nRubyVM::YJIT.enable(mem_size: ENV['YJIT_MEM_SIZE']&.to_i)  # nil or Integer","handlingStrategy":"type-guard","validationCode":"mem = config.fetch(:yjit_mem_size, nil)\nmem = Integer(mem) if mem.is_a?(String)  # strict cast; raises early on garbage\nRubyVM::YJIT.enable(mem_size: mem) if mem.nil? || mem.is_a?(Integer)","typeGuard":"# Exact check YJIT itself performs; note Float 64.0 is rejected by design\ndef yjit_integer?(v)\n  v.is_a?(Integer)\nend","tryCatchPattern":"begin\n  RubyVM::YJIT.enable(mem_size: mem)\nrescue ArgumentError => e\n  warn \"YJIT config rejected (#{e.message}); enabling with defaults\"\n  RubyVM::YJIT.enable\nend","preventionTips":["Convert ENV and YAML values with to_i (or strict Integer()) at the config boundary","Remember Floats are rejected even when whole: use Integer literals","Add a config-loading spec that asserts types before they reach YJIT.enable"],"tags":["ruby","yjit","argumenterror","type-validation","mem-size"],"backgroundTag":"wrong-argument-type","analyzedSha":"0e5b888e1c355f3f728f2659f085820937dada48","analyzedAt":"2026-08-21T14:25:43.473Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}