Ruby Issue Tracking System: Issueshttps://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112019-11-30T02:13:00ZRuby Issue Tracking System
Redmine Ruby master - Bug #16382 (Closed): SystemStackError thrown when running `LC_ALL="C" RUBYLIB=".:" ...https://bugs.ruby-lang.org/issues/163822019-11-30T02:13:00Zyuki24 (Yuki Nishijima)yk.nishijima@gmail.com
<a name="Steps-to-reproduce"></a>
<h2 >Steps to reproduce<a href="#Steps-to-reproduce" class="wiki-anchor">¶</a></h2>
<pre><code>~/GitHub/ruby/did_you_mean/テスト$ LC_ALL="C" RUBYLIB=".:" ruby -E cp932:utf-8 aaa.rb
Traceback (most recent call last):
2: from <internal:gem_prelude>:5:in `<internal:gem_prelude>'
1: from /Users/yuki/.rbenv/versions/2.7.0-dev/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'
/Users/yuki/.rbenv/versions/2.7.0-dev/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require': stack level too deep (SystemStackError)
</code></pre>
<p>The key points are:</p>
<ul>
<li>The current directory contains one or more Japanese character (perhaps non-alphabet char is what's causing the issue, but I'm unfamiliar with other types of chars)</li>
<li>Only happens when <code>LC_ALL="C" RUBYLIB=".:"</code> environment variables and the option <code>-E cp932:utf-8</code> are given</li>
<li>The existing of the file that is supposed to be run by the executable does not seem to matter</li>
</ul>
<a name="Actual"></a>
<h2 >Actual<a href="#Actual" class="wiki-anchor">¶</a></h2>
<p>A <code>SystemStackError</code> is thrown.</p>
<a name="Expected"></a>
<h2 >Expected<a href="#Expected" class="wiki-anchor">¶</a></h2>
<p>The file specified should be run or Ruby should throw a <code>No such file or directory -- aaa.rb (LoadError)</code> error.</p> Ruby master - Feature #16363 (Closed): Promote did_you_mean to default gemhttps://bugs.ruby-lang.org/issues/163632019-11-24T00:27:44Zyuki24 (Yuki Nishijima)yk.nishijima@gmail.com
<p>The <code>did_you_mean</code> gem has been a bundled gem for over 3 years now and I think it's time to promote it to a standard library. There are two main issues in the current structure:</p>
<ul>
<li>A number of implementations, including <a href="https://github.com/ruby/ruby/blob/fb6a489af2765a3b56e301adf0019af6bbad6156/lib/optparse.rb#L1792" class="external"><code>optparse.rb</code></a>, <a href="https://github.com/ruby/rake/blob/985abffa9954d21790831d9626d9c38b24a94199/lib/rake/task_manager.rb#L69-L78" class="external">rake</a>, and <a href="https://github.com/rails/rails/blob/98a57aa5f610bc66af31af409c72173cdeeb3c9e/railties/lib/rails/command/spellchecker.rb#L8" class="external">rails</a>, now take advantage of the gem's spell checker, but it's awkward to have to check the existence of the <code>DidYouMean::SpellChecker</code> constant.</li>
<li>there are some problems with regard to bundler + did_you_mean because of did_you_mean being a bundled gem. Since the vendored version of thor inside bundler and ruby itself explicitly requires did_you_mean, it can become difficult to load it when using Bundler.setup. See this issue: <a href="https://github.com/yuki24/did_you_mean/issues/117#issuecomment-482733159" class="external">https://github.com/yuki24/did_you_mean/issues/117#issuecomment-482733159</a> for more details.</li>
</ul>
<p>I would like to promote the gem up to a standard library and make it always available, so we can always reliably require it whenever we want to.</p>
<p>A patch could be found here: <a href="https://github.com/ruby/ruby/pull/2689" class="external">https://github.com/ruby/ruby/pull/2689</a></p> Ruby master - Feature #12043 (Closed): Add a method to NoMethodError that tells if private method...https://bugs.ruby-lang.org/issues/120432016-02-01T12:22:18Zyuki24 (Yuki Nishijima)yk.nishijima@gmail.com
<p>I've briefly talked about this to Sasada-san, but also wanted to hear from other committers. I would like to add a method to <code>NoMethodError</code> that tells whether or not private methods are callable from the line where the exception is raised. An example would be like this:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">begin</span>
<span class="n">raies</span> <span class="s2">"Error"</span> <span class="c1"># </span>
<span class="k">rescue</span> <span class="no">NoMethodError</span> <span class="o">=></span> <span class="n">no_method_error</span>
<span class="n">no_method_error</span><span class="p">.</span><span class="nf">private_method_callable?</span> <span class="c1"># => true</span>
<span class="k">end</span>
</code></pre>
<p>The only use case I can think of is <a href="https://github.com/yuki24/did_you_mean/blob/c4f0247/lib/did_you_mean/spell_checkers/method_name_checker.rb#L18" class="external">the spell checker in the did_you_mean gem</a> and I'm not actually sure how useful it would be for others.</p>
<p>Please let me know what you think, I'm open to suggestions.</p> Ruby master - Feature #12042 (Feedback): A better interface that returns a list of local variable...https://bugs.ruby-lang.org/issues/120422016-02-01T12:16:30Zyuki24 (Yuki Nishijima)yk.nishijima@gmail.com
<p>We've changed the behavior of <code>NameError#local_variables</code> as discussed on <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Change NameError#local_variables to return the list of local variables where the method is raised (Closed)" href="https://bugs.ruby-lang.org/issues/11777">#11777</a>, but I'm not actually satisfied by the change. This change has made it impossible to get a list of local variables available within a NameError scope. It would be nice, if we could add a new method that does what <code>NameError#local_variables</code> does right now, and change the <code>local_variables</code> method back to the previous behavior.</p>
<p>I actually don't have a good name in mind, but please let me know if anyone has a good name for it.</p> Ruby master - Feature #12041 (Open): Change the initializer of NameError to take a receiver as th...https://bugs.ruby-lang.org/issues/120412016-02-01T11:42:34Zyuki24 (Yuki Nishijima)yk.nishijima@gmail.com
<p>I would like to change <code>NameError#initialize</code> to take a receiver object as the third argument. An example would be like this:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">receiver_object</span> <span class="o">=</span> <span class="no">Object</span><span class="p">.</span><span class="nf">new</span>
<span class="n">name_error</span> <span class="o">=</span> <span class="no">NameError</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="s2">"Error message"</span><span class="p">,</span> <span class="s2">"name"</span><span class="p">,</span> <span class="n">receiver_object</span><span class="p">)</span>
<span class="n">name_error</span><span class="p">.</span><span class="nf">receiver</span><span class="p">.</span><span class="nf">equal?</span><span class="p">(</span><span class="n">receiver_object</span><span class="p">)</span> <span class="c1"># => true</span>
</code></pre>
<p>The reason I wanted this change is Rails overrides <code>Module#const_missing</code> and <a href="https://github.com/rails/rails/blob/23b6f65/activesupport/lib/active_support/dependencies.rb#L567-L569" class="external">raises an NameError without a receiver object</a>. It has actually affected one of the did_you_mean's spell checkers and thus no suggestions for constant names will be made on Rails. One more use case I can think of is when there's a class that inherits from <code>NameError</code> or <code>NoMethodError</code> and an arbitrary receiver needs to be passed to the initializer of the class.</p>
<p>Please let me know if you have any thoughts.</p> Ruby master - Feature #11905 (Closed): Change the 'class' keyword to return a symbolhttps://bugs.ruby-lang.org/issues/119052015-12-28T08:00:19Zyuki24 (Yuki Nishijima)yk.nishijima@gmail.com
<p>Currently the <code>class</code> keyword returns nil:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">class</span> <span class="nc">Person</span><span class="p">;</span> <span class="k">end</span> <span class="c1"># => nil</span>
</code></pre>
<p>It would be great if it could return a symbol instead:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">class</span> <span class="nc">Person</span><span class="p">;</span> <span class="k">end</span> <span class="c1"># => :Person</span>
</code></pre>
<p>If we make it so we'll be able to do something like below:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">private_constant</span> <span class="k">class</span> <span class="nc">User</span>
<span class="o">...</span>
<span class="k">end</span>
</code></pre> Ruby master - Feature #11777 (Closed): Change NameError#local_variables to return the list of loc...https://bugs.ruby-lang.org/issues/117772015-12-06T06:15:26Zyuki24 (Yuki Nishijima)yk.nishijima@gmail.com
<p>Sasada-san and I talked about this briefly a few weeks ago, but I also wanted to let others know about this.</p>
<p>This change will make it possible to pull out the list of local variables where the exception is raised without TracePoint. The <code>did_you_mean</code> gem uses TracePoint, and the current code looks like this:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="c1"># lib/did_you_mean.rb</span>
<span class="no">TracePoint</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="ss">:raise</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">tp</span><span class="o">|</span>
<span class="n">e</span> <span class="o">=</span> <span class="n">tp</span><span class="p">.</span><span class="nf">raised_exception</span>
<span class="k">if</span> <span class="no">SPELL_CHECKERS</span><span class="p">.</span><span class="nf">include?</span><span class="p">(</span><span class="n">e</span><span class="p">.</span><span class="nf">class</span><span class="p">.</span><span class="nf">to_s</span><span class="p">)</span> <span class="o">&&</span> <span class="o">!</span><span class="n">e</span><span class="p">.</span><span class="nf">instance_variable_defined?</span><span class="p">(</span><span class="ss">:@frame_binding</span><span class="p">)</span>
<span class="n">e</span><span class="p">.</span><span class="nf">instance_variable_set</span><span class="p">(</span><span class="ss">:@frame_binding</span><span class="p">,</span> <span class="n">tp</span><span class="p">.</span><span class="nf">binding</span><span class="p">)</span>
<span class="k">end</span>
<span class="k">end</span><span class="p">.</span><span class="nf">enable</span>
<span class="c1"># lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb</span>
<span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="n">exception</span><span class="p">)</span>
<span class="o">...</span>
<span class="vi">@lvar_names</span> <span class="o">=</span> <span class="n">exception</span><span class="p">.</span><span class="nf">frame_binding</span><span class="p">.</span><span class="nf">local_variables</span>
<span class="o">...</span>
<span class="k">end</span>
</code></pre>
<p>If we change <code>NameError#local_variables</code> as described it'll look like this:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="c1"># lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb</span>
<span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="n">exception</span><span class="p">)</span>
<span class="vi">@lvar_names</span> <span class="o">=</span> <span class="n">exception</span><span class="p">.</span><span class="nf">local_variables</span>
<span class="o">...</span>
<span class="k">end</span>
</code></pre>
<p>The problem with TracePoint is that it's still a little buggy (also see <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: SEGV instead of SystemStackError when using the TracePoint API (Closed)" href="https://bugs.ruby-lang.org/issues/11668">#11668</a>, <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Ruby process crashes when TracePoint.new(:raise) is enabled and SystemStackError is raised (Closed)" href="https://bugs.ruby-lang.org/issues/11667">#11667</a>) and also makes Ruby slower <a href="https://twitter.com/_ko1/status/657599422566543360" class="external">as reported by Sasada-san</a>. I would like to change the behaviour of <code>NameError#local_variables</code> and remove the use of TracePoint from the gem entirely so we can make the gem much more stable.</p> Ruby master - Bug #11667 (Closed): Ruby process crashes when TracePoint.new(:raise) is enabled an...https://bugs.ruby-lang.org/issues/116672015-11-09T03:17:56Zyuki24 (Yuki Nishijima)yk.nishijima@gmail.com
<p>Let's say a <code>TracePoint.new(:raise)</code> is enabled. When a method that recursively calls itself, the Ruby process will just die rather than raising a SystemStackError.</p>
<pre><code>$ ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
$ irb
2.2.3 :001 > TracePoint.new(:raise){}.enable
=> false
2.2.3 :002 > def f(i); f(i-1); end; f(10_000)
/usr/local/rvm/rubies/ruby-2.2.3/bin/irb: exception reentered (fatal)
</code></pre>
<pre><code>$ ruby -v
ruby 2.3.0dev (2015-10-23 trunk 52247) [x86_64-linux]
$ irb
head :001 > TracePoint.new(:raise){|tp| tp.raised_exception }.enable
=> false
head :002 > def f(i); f(i-1); end; f(10_000)
/usr/local/rvm/rubies/ruby-head/bin/irb: exception reentered (fatal)
</code></pre>
<p>I expect this code to raise <code>SystemStackError</code> instead.</p> Ruby master - Feature #11477 (Closed): NameError#qualified_namehttps://bugs.ruby-lang.org/issues/114772015-08-22T08:59:12Zyuki24 (Yuki Nishijima)yk.nishijima@gmail.com
<p>Hi,</p>
<p>This is a followup issue to <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Integrated "did_you_mean" gem to ruby-core (Closed)" href="https://bugs.ruby-lang.org/issues/11252">#11252</a>. I'd like to add a method that basically does the same thing as <a href="https://github.com/rails/rails/blob/ebe73abea0ae02094ddc28f8fd60ae92373b6113/activesupport/lib/active_support/core_ext/name_error.rb#L2-L14" class="external">NameError#missing_name</a>. This will allow gems like Rails and did_you_mean to get a qualified name without parsing an error message.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">begin</span>
<span class="no">HelloWorld</span>
<span class="k">rescue</span> <span class="no">NameError</span> <span class="o">=></span> <span class="n">e</span>
<span class="n">error</span><span class="p">.</span><span class="nf">name</span> <span class="c1"># => :HelloWorld</span>
<span class="n">error</span><span class="p">.</span><span class="nf">qualified_name</span> <span class="c1"># => :HelloWorld</span>
<span class="k">end</span>
<span class="k">begin</span>
<span class="no">String</span><span class="o">::</span><span class="no">DoesntExist</span>
<span class="k">rescue</span> <span class="no">NameError</span> <span class="o">=></span> <span class="n">e</span>
<span class="n">error</span><span class="p">.</span><span class="nf">name</span> <span class="c1"># => :DoesntExist</span>
<span class="n">error</span><span class="p">.</span><span class="nf">qualified_name</span> <span class="c1"># => :"String::DoesntExist"</span>
<span class="k">end</span>
</code></pre>
<p>I'm not actually sure what it should return when the module/class is an anonymous module/class, but one thing we can do is just use the result of <code>#to_s</code>:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">m</span> <span class="o">=</span> <span class="no">Module</span><span class="p">.</span><span class="nf">new</span>
<span class="k">begin</span>
<span class="n">m</span><span class="o">::</span><span class="no">DoesntExist</span>
<span class="k">rescue</span> <span class="no">NameError</span> <span class="o">=></span> <span class="n">e</span>
<span class="n">error</span><span class="p">.</span><span class="nf">name</span> <span class="c1"># => :DoesntExist</span>
<span class="n">error</span><span class="p">.</span><span class="nf">qualified_name</span> <span class="c1"># => :"#<Module:0x0000000260c2f8>::DoesntExist"</span>
<span class="k">end</span>
</code></pre>
<p>I'm open to suggestions. Let me know what you think.</p>
<p>Yuki</p> Ruby master - Bug #10970 (Closed): Backport r49867https://bugs.ruby-lang.org/issues/109702015-03-13T23:18:01Zyuki24 (Yuki Nishijima)yk.nishijima@gmail.com
<p>Please backport r49867 to 2.0, 2.1 and 2.2 as well.</p> Ruby master - Feature #10882 (Open): Provide Levenshtein distance implementation as part of stdlibhttps://bugs.ruby-lang.org/issues/108822015-02-21T20:50:04Zyuki24 (Yuki Nishijima)yk.nishijima@gmail.com
<p><a href="http://en.wikipedia.org/wiki/Levenshtein_distance" class="external">Levenshtein distance algorithm</a> has been used by Rubygems, Bundler, did_you_mean and Rails and I think it's popular enough to provide it as part of Ruby's stdlib. It still seems a bit too high-level though, but definitely useful (e.g. <a href="https://github.com/ruby/rake/pull/29" class="external">adding "did you mean?" to rake</a>).</p>
<p>API-wise, I would like to propose something like the following, but I'm totally open to hear the core team's opinions as I'm not sue if this is great.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="nb">require</span> <span class="s1">'distance'</span>
<span class="no">Distance</span><span class="p">.</span><span class="nf">levenshtein</span><span class="p">(</span><span class="n">str1</span><span class="p">,</span> <span class="n">str2</span><span class="p">)</span>
</code></pre>
<p>It would also be interesting to have <code>#distance</code> method on <code>String</code>:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="s2">"word"</span><span class="p">.</span><span class="nf">distance</span><span class="p">(</span><span class="s2">"other"</span><span class="p">)</span>
</code></pre>
<p>which is implemented as:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">def</span> <span class="nf">distance</span><span class="p">(</span><span class="n">str</span><span class="p">,</span> <span class="n">algorithm</span> <span class="o">=</span> <span class="ss">:levenshtein</span><span class="p">)</span>
<span class="c1"># calculate the distance here.</span>
<span class="k">end</span>
</code></pre>
<p>so it can allow to change the algorythm when we add more (e.g. <a href="http://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance" class="external">Jaro–Winkler distance</a>).</p> Ruby master - Feature #10881 (Closed): NoMethodError#receieverhttps://bugs.ruby-lang.org/issues/108812015-02-21T20:22:58Zyuki24 (Yuki Nishijima)yk.nishijima@gmail.com
<p>I would like <code>NoMethodError</code> to have <code>receiver</code> method:</p>
<pre><code>receiver = "receiver"
exception = receiver.doesnt_exist rescue $!
exception.receiver == receiver # => true
</code></pre>
<p>This helps did_you_mean gem implement its features without having native C exceptions, and also makes it easier to add "did you mean?" feature to irb. Let mw know what you think. Thanks!</p> Ruby master - Bug #10847 (Closed): SystemStackError after NameError prepends a modulehttps://bugs.ruby-lang.org/issues/108472015-02-12T13:50:23Zyuki24 (Yuki Nishijima)yk.nishijima@gmail.com
<p>The following code causes <code>SystemStackError</code>.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">module</span> <span class="nn">Foo</span>
<span class="k">end</span>
<span class="no">NameError</span><span class="p">.</span><span class="nf">prepend</span> <span class="no">Foo</span>
<span class="n">foo</span> <span class="k">rescue</span> <span class="vg">$!</span>
</code></pre>
<p>And here is the full backtrace:</p>
<pre><code>system_stack_error_from_name_error.rb:3:in `initialize': stack level too deep (SystemStackError)
from system_stack_error_from_name_error.rb:3:in `initialize'
from system_stack_error_from_name_error.rb:3:in `initialize'
from system_stack_error_from_name_error.rb:3:in `initialize'
from system_stack_error_from_name_error.rb:3:in `initialize'
from system_stack_error_from_name_error.rb:3:in `initialize'
from system_stack_error_from_name_error.rb:3:in `initialize'
from system_stack_error_from_name_error.rb:3:in `initialize'
from system_stack_error_from_name_error.rb:3:in `initialize'
... 10907 levels...
from system_stack_error_from_name_error.rb:3:in `initialize'
from system_stack_error_from_name_error.rb:3:in `initialize'
from system_stack_error_from_name_error.rb:3:in `method_missing'
from system_stack_error_from_name_error.rb:3:in `<main>'
</code></pre>
<p>This happens on Ruby 2.0.0, 2,1,5, 2.2.0 and ruby-trunk(rev 49451).</p> Ruby master - Bug #6645 (Rejected): Segmentation fault in net/http.rbhttps://bugs.ruby-lang.org/issues/66452012-06-25T23:59:43Zyuki24 (Yuki Nishijima)yk.nishijima@gmail.com
<p>=begin<br>
Today I ran into the problem titled above. The error message looks like this:</p>
<p>/home/yuki/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:761: [BUG] Segmentation fault<br>
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]</p>
<p>-- Control frame information -----------------------------------------------<br>
c:0066 p:0015 s:0266 b:0264 l:000263 d:000263 METHOD /home/yuki/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:761<br>
c:0065 p:0011 s:0256 b:0256 l:000255 d:000255 METHOD /home/yuki/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:755<br>
c:0064 p:0048 s:0253 b:0253 l:000252 d:000252 METHOD /home/yuki/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:744<br>
c:0063 p:0182 s:0250 b:0250 l:000249 d:000249 METHOD /home/yuki/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:557</p>
<p>You can find the full stack trace here: ((<a href="URL:https://gist.github.com/2988740" class="external">URL:https://gist.github.com/2988740</a>))</p>
<p>I don't know how I can help the project here since this is my first time to report a bug, but let me know if you would like me to do something. Thanks!<br>
=end</p>