{"record":{"id":"fe20de921e95c184","repo":"awesome-print/awesome_print","slug":"object-doesn-t-support-ai","errorCode":null,"errorMessage":"(Object doesn't support #ai)","messagePattern":"\\(Object doesn't support #ai\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"lib/awesome_print/custom_defaults.rb","lineNumber":33,"sourceCode":"\n    def rails_console?\n      console? && boolean(defined?(Rails::Console) || ENV['RAILS_ENV'])\n    end\n\n    def diet_rb\n      IRB.formatter = Class.new(IRB::Formatter) do\n        def inspect_object(object)\n          object.ai\n        end\n      end.new\n    end\n\n    def usual_rb\n      IRB::Irb.class_eval do\n        def output_value(*args)\n          ap @context.last_value\n        rescue NoMethodError\n          puts \"(Object doesn't support #ai)\"\n        end\n      end\n    end\n\n    def irb!\n      return unless defined?(IRB)\n\n      IRB.version.include?('DietRB') ? diet_rb : usual_rb\n    end\n\n    def pry!\n      Pry.print = proc { |output, value| output.puts value.ai } if defined?(Pry)\n    end\n\n    private\n\n    # Takes a value and returns true unless it is false or nil\n    # This is an alternative to the less readable !!(value)","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/awesome-print/awesome_print/blob/8a7ff0aabacbebf694c3e27242809219a96d5a3b/lib/awesome_print/custom_defaults.rb#L15-L51","documentation":"This message comes from awesome_print's IRB integration: AwesomePrint.irb! (custom_defaults.rb:28, usual_rb) monkey-patches IRB::Irb#output_value so that after every statement, IRB prints the result with ap @context.last_value instead of the stock inspector. ap (core_ext/kernel.rb:20) calls object.ai, a method awesome_print defines on Kernel — so any value that does not have Kernel's methods, most commonly a BasicObject/BlankSlate instance, raises NoMethodError, which this rescue converts into the placeholder line. The session keeps running; only that one value is not displayed. It never happens from a plain ap obj in scripts — there the NoMethodError propagates to your code normally.","triggerScenarios":"An IRB or rails console session started with the awesome_print patch active (require 'awesome_print'; AwesomePrint.irb! — typically in ~/.irbrc or ~/.aprc), then evaluating an expression whose return value lacks Kernel#ai: BasicObject.new, a library BasicObject/blank-slate proxy (DSL wrappers, null objects), or an object that undefs ai or whose method_missing raises NoMethodError. Each such statement prints '(Object doesn't support #ai)' instead of => value.","commonSituations":"Consoles configured to auto-pretty-print every result while exploring code built on BasicObject proxies or null-object patterns; DSL gems exposing blank-slate objects; .irbrc shared across projects where one project's decorators behave differently; developers mistaking the line for a crash inside their own code.","solutions":["Treat it as informational: re-run the expression into a local (v = expr) and print through Kernel directly — Kernel.instance_method(:inspect).bind(v).call — because BasicObject intentionally has no methods, not even #inspect or #to_s.","If the object is a library proxy, use that library's own rendering API (its documented to_s wrapper or inspector) instead of relying on console auto-print.","Stop auto-patching IRB: remove AwesomePrint.irb! from ~/.irbrc / ~/.aprc so stock IRB result printing is restored, and call ap obj explicitly only where you want it.","Replace the patch with a guarded one in ~/.irbrc that checks #ai via Kernel binding and falls back to plain printing for objects that lack it."],"exampleFix":"# before (~/.irbrc) — every console result is forced through #ai\nrequire 'awesome_print'\nAwesomePrint.irb!\n\n# after — keep stock IRB printing; pretty-print on demand\nrequire 'awesome_print'\n# ap my_object  # explicit, only for objects that support #ai","handlingStrategy":"type-guard","validationCode":"# Before printing an arbitrary value with ap/ai (works even for BasicObject)\nprintable = begin\n  Kernel.instance_method(:respond_to?).bind(value).call(:ai)\nrescue TypeError, NoMethodError\n  false\nend\nap(value) if printable","typeGuard":"def ap_printable?(obj)\n  Kernel.instance_method(:respond_to?).bind(obj).call(:ai)\nrescue StandardError\n  false # BasicObject and stripped objects land here (bind raises TypeError for non-Kernel instances)\nend","tryCatchPattern":"begin\n  ap value\nrescue NoMethodError\n  # BasicObject has no inspect/to_s either — go through Kernel\n  puts Kernel.instance_method(:inspect).bind(value).call\nend","preventionTips":["Prefer explicit ap obj calls over AwesomePrint.irb! auto-patching of IRB result printing.","In auto-printing consoles, end BasicObject-producing expressions with a printable value: obj = make_proxy; :done.","Wrap blank-slate objects in a decorator or Struct that includes Kernel before console inspection.","Test .irbrc/.aprc changes by evaluating BasicObject.new once to confirm fallback behavior."],"tags":["ruby","irb","awesome-print","basicobject","nomethoderror","monkey-patching"],"backgroundTag":"nomethoderror-undefined-method","analyzedSha":"8a7ff0aabacbebf694c3e27242809219a96d5a3b","analyzedAt":"2026-08-23T02:33:16.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}