From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id B540917DB81B for ; Fri, 12 Sep 2014 16:07:45 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (smtp.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 63A49B5D8CF for ; Fri, 12 Sep 2014 15:47:37 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 41CC697A832 for ; Fri, 12 Sep 2014 15:47:39 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Authentication-Results: funfun.nagaokaut.ac.jp (amavisd-new); dkim=fail (1024-bit key) reason="fail (message has been altered)" header.d=sendgrid.me Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tFqgEAZ8_hHL for ; Fri, 12 Sep 2014 15:47:38 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id D1DF397A827 for ; Fri, 12 Sep 2014 15:47:38 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 60C54952439 for ; Fri, 12 Sep 2014 15:47:35 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 130EE120466; Fri, 12 Sep 2014 15:47:29 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o10.shared.sendgrid.net (o10.shared.sendgrid.net [173.193.132.135]) by neon.ruby-lang.org (Postfix) with ESMTPS id 03D4D12040B for ; Fri, 12 Sep 2014 15:47:25 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=uuEoJIN1P+e8dxxGKILlYs2x/cA=; b=OBJUY/g7gMysIbt8Hj DQn+2TZSh/aYmhKPSZcPMA0S71AVhkdq8j6VryUQtWFpCFsNl4Kxf8GTG+MJTWp4 DzYrLHsKW0M/S8K2ezfNSwLhkcz5sBy6GFOntKiV36xdh7TpaFfHXxSmDlT0qtEs 1ac+z1WWm0sDXy4GaxWY5tmmI= Received: by mf174.sendgrid.net with SMTP id mf174.5139.541296F914 2014-09-12 06:47:21.663687051 +0000 UTC Received: from herokuapp.com (ec2-54-196-9-89.compute-1.amazonaws.com [54.196.9.89]) by ismtpd-025.iad1.sendgrid.net (SG) with ESMTP id 148689dbeb3.66bc.edb715 Fri, 12 Sep 2014 06:47:21 +0000 (GMT) Date: Fri, 12 Sep 2014 06:47:21 +0000 From: myron.marston@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 39218 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 8982 X-Redmine-Issue-Author: myronmarston X-Redmine-Sender: myronmarston X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: OOF Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS7wy9N0QsFUoAUUtXAbnhcD+QZkpMhaemQboXNjengJqp/Us3qIz1m/NT5jJnUw9SL46KLGMdnfZ5LWvgmfPzyBO7pRUyORfgz2Sc4LE+HZNcQuczGZAaq654Cfr6wjc8A= X-ML-Name: ruby-core X-Mail-Count: 64990 Subject: [ruby-core:64990] [ruby-trunk - Bug #8982] NoMethodError#message produces surprising output when #inspect is defined on an anonymous class X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #8982 has been updated by Myron Marston. So I've run into this issue again, and as it turns out, this is a much more widespread problem than I first thought. I originally thought that this was just a problem with anonymous classes, but that's not the case; now I'm running up against it in RSpec. We're trying to define `RSpec::Core::ExampleGroup#inspect` so that when users have a typo (or otherwise trigger a `NoMethodError` for a message sent to an example group) the example group is represented in the error message in a pretty, useful way, rather than having the obscure hex value: https://github.com/rspec/rspec-core/issues/1590 https://github.com/rspec/rspec-core/pull/1687 As far as I can tell, it's impossible to achieve this behavior on MRI, and that really bums me out :(. Any chance this can get fixed in Ruby 2.2? ---------------------------------------- Bug #8982: NoMethodError#message produces surprising output when #inspect is defined on an anonymous class https://bugs.ruby-lang.org/issues/8982#change-48867 * Author: Myron Marston * Status: Open * Priority: Normal * Assignee: * Category: * Target version: * ruby -v: ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0] * Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN ---------------------------------------- =begin Given the following script: def raise_no_method_error_for_anonymous_class_with_inspect(&block) klass = Class.new do define_method(:inspect, &block) end begin instance = klass.new puts "#inspect output: #{instance.inspect} (#{instance.inspect.length} chars)" instance.undefined_method rescue NoMethodError => e puts e.message end puts end raise_no_method_error_for_anonymous_class_with_inspect do "#" end raise_no_method_error_for_anonymous_class_with_inspect do "" end raise_no_method_error_for_anonymous_class_with_inspect do "#" end raise_no_method_error_for_anonymous_class_with_inspect do "#" end It produces the following output: #inspect output: # (19 chars) undefined method `undefined_method' for # #inspect output: (18 chars) undefined method `undefined_method' for :# #inspect output: # (65 chars) undefined method `undefined_method' for # #inspect output: # (66 chars) undefined method `undefined_method' for #<#:0x101726698> There are two surprising things here: * It matters whether or not the first character in my `inspect` is a `#`. If it's not, ruby appends the class's `#inspect` output to it. * It matters how long my `inspect` string is. If it's less than 66 characters, it's used; if it's more than 65, it's discarded, and the default anonymous `#inspect` is used instead. Both of these things are extremely surprising and seem very arbitrary and inconsistent. I brought this up on ruby parley and @charliesome was kind enough to point me to the code that's the source of this issue: (()) So it looks intentional, but I think this is a bug. =end -- https://bugs.ruby-lang.org/