https://bugs.ruby-lang.org/
https://bugs.ruby-lang.org/favicon.ico?1711330511
2017-05-11T18:36:01Z
Ruby Issue Tracking System
Ruby master - Feature #13557: there's no way to pass backtrace locations as a massaged backtrace
https://bugs.ruby-lang.org/issues/13557?journal_id=64753
2017-05-11T18:36:01Z
sylvain.joyeux (Sylvain Joyeux)
<ul></ul><p>Did a mistake. The code example uses <code>caller_locations</code> (and therefore causes the <code>TypeError</code> exception) while I meant it to use <code>caller</code> and therefore cause <code>e.backtrace_locations</code> to be nil</p>
Ruby master - Feature #13557: there's no way to pass backtrace locations as a massaged backtrace
https://bugs.ruby-lang.org/issues/13557?journal_id=64754
2017-05-11T20:49:56Z
Eregon (Benoit Daloze)
<ul></ul><p>+1 This would be a nice feature and let the VM still keep the backtrace information in an flexible way (instead of dumping it to a String like Exception#backtrace).</p>
Ruby master - Feature #13557: there's no way to pass backtrace locations as a massaged backtrace
https://bugs.ruby-lang.org/issues/13557?journal_id=78838
2019-06-24T20:21:02Z
jeremyevans0 (Jeremy Evans)
merch-redmine@jeremyevans.net
<ul><li><strong>Tracker</strong> changed from <i>Bug</i> to <i>Feature</i></li><li><strong>ruby -v</strong> deleted (<del><i>ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-linux], ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]</i></del>)</li><li><strong>Backport</strong> deleted (<del><i>2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN</i></del>)</li></ul>
Ruby master - Feature #13557: there's no way to pass backtrace locations as a massaged backtrace
https://bugs.ruby-lang.org/issues/13557?journal_id=106824
2024-02-16T17:01:18Z
byroot (Jean Boussier)
byroot@ruby-lang.org
<ul></ul><p>I'll try to find some time to implement this in the near future, because I just ran into this today, and resorted to the following hack:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">unless</span> <span class="n">exception</span><span class="p">.</span><span class="nf">backtrace</span>
<span class="k">begin</span>
<span class="k">raise</span> <span class="n">exception</span>
<span class="k">rescue</span> <span class="n">exception</span><span class="p">.</span><span class="nf">class</span> <span class="o">=></span> <span class="n">raised_exception</span>
<span class="n">raised_exception</span><span class="p">.</span><span class="nf">backtrace</span><span class="p">.</span><span class="nf">shift</span>
<span class="n">raised_exception</span><span class="p">.</span><span class="nf">backtrace_locations</span><span class="p">.</span><span class="nf">shift</span>
<span class="n">exception</span> <span class="o">=</span> <span class="n">raised_exception</span>
<span class="k">end</span>
<span class="k">end</span>
</code></pre>
<p>I think both <code>Kernel#raise</code> and <code>Exception#set_backtrace</code> would need to accept array of <code>Thread::Backtrace::Location</code>.</p>
Ruby master - Feature #13557: there's no way to pass backtrace locations as a massaged backtrace
https://bugs.ruby-lang.org/issues/13557?journal_id=106835
2024-02-16T23:10:47Z
Dan0042 (Daniel DeLorme)
<ul></ul><blockquote>
<p>I think both <code>Kernel#raise</code> and <code>Exception#set_backtrace</code> would need to accept array of <code>Thread::Backtrace::Location</code>.</p>
</blockquote>
<p>That's an idea I fully support. Although when I need to modify an error's backtrace 95% of the time it's because I want to skip the first few frames, like <code>raise Error, "message", caller[3..-1]</code>. So it would be nice to have a shortcut idiom for this, like perhaps <code>raise Error, "message", skip: 3</code></p>
Ruby master - Feature #13557: there's no way to pass backtrace locations as a massaged backtrace
https://bugs.ruby-lang.org/issues/13557?journal_id=106869
2024-02-19T10:57:12Z
byroot (Jean Boussier)
byroot@ruby-lang.org
<ul></ul><p>Proposed patch here if someone feels like reviewing it: <a href="https://github.com/ruby/ruby/pull/10017" class="external">https://github.com/ruby/ruby/pull/10017</a></p>
Ruby master - Feature #13557: there's no way to pass backtrace locations as a massaged backtrace
https://bugs.ruby-lang.org/issues/13557?journal_id=106870
2024-02-19T12:15:25Z
byroot (Jean Boussier)
byroot@ruby-lang.org
<ul></ul><blockquote>
<p>So it would be nice to have a shortcut idiom for this, like perhaps raise Error, "message", skip: 3</p>
</blockquote>
<p>With my patch it would be:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">raise</span> <span class="no">Error</span><span class="p">,</span> <span class="s2">"message"</span><span class="p">,</span> <span class="n">caller_locations</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
</code></pre>
<p>Which I think is simple enough to not warrant and extra <code>skip:</code> parameter to <code>raise</code>.</p>
Ruby master - Feature #13557: there's no way to pass backtrace locations as a massaged backtrace
https://bugs.ruby-lang.org/issues/13557?journal_id=106888
2024-02-19T23:07:43Z
Dan0042 (Daniel DeLorme)
<ul></ul><p>byroot (Jean Boussier) wrote in <a href="#note-7">#note-7</a>:</p>
<blockquote>
<p>Which I think is simple enough to not warrant and extra <code>skip:</code> parameter to <code>raise</code>.</p>
</blockquote>
<p>Good point, I'm convinced.</p>
Ruby master - Feature #13557: there's no way to pass backtrace locations as a massaged backtrace
https://bugs.ruby-lang.org/issues/13557?journal_id=107178
2024-03-12T04:26:54Z
nobu (Nobuyoshi Nakada)
nobu@ruby-lang.org
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/107178/diff?detail_id=66579">diff</a>)</li></ul>
Ruby master - Feature #13557: there's no way to pass backtrace locations as a massaged backtrace
https://bugs.ruby-lang.org/issues/13557?journal_id=107179
2024-03-12T04:28:02Z
ko1 (Koichi Sasada)
<ul></ul><p>I'm not against but could you summarize usages?</p>
Ruby master - Feature #13557: there's no way to pass backtrace locations as a massaged backtrace
https://bugs.ruby-lang.org/issues/13557?journal_id=107188
2024-03-12T07:23:03Z
byroot (Jean Boussier)
byroot@ruby-lang.org
<ul></ul><p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/17">@ko1 (Koichi Sasada)</a> all the same use cases arrays of strings are currently used for:</p>
<p>E.g. raising an error with an existing backtrace:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">raise</span> <span class="no">NicerError</span><span class="p">,</span> <span class="s2">"some message"</span><span class="p">,</span> <span class="n">original_error</span><span class="p">.</span><span class="nf">backtrace_locations</span>
</code></pre>
<p>Or with some frames skipped:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">raise</span> <span class="no">SomeError</span><span class="p">,</span> <span class="s2">"some message"</span><span class="p">,</span> <span class="n">caller_locations</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="c1"># skip 2 frames</span>
</code></pre>
<p>Creating an exception with a thread backtrace:</p>
<pre><code class="ruby syntaxhl" data-language="ruby">
<span class="n">async_error</span> <span class="o">=</span> <span class="no">SomeError</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="s2">"thread timed out"</span><span class="p">)</span>
<span class="n">async_error</span><span class="p">.</span><span class="nf">set_backtrace</span><span class="p">(</span><span class="n">other_thread</span><span class="p">.</span><span class="nf">backtrace_locations</span><span class="p">)</span>
<span class="n">report</span><span class="p">(</span><span class="n">async_error</span><span class="p">)</span>
</code></pre>
<p>And probably plenty others I'm not thinking of. This is only an improved version of passing <code>set_backtrace(exc.backtrace)</code>.</p>
Ruby master - Feature #13557: there's no way to pass backtrace locations as a massaged backtrace
https://bugs.ruby-lang.org/issues/13557?journal_id=107247
2024-03-14T10:38:50Z
byroot (Jean Boussier)
byroot@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="`Exception#set_backtrace` accept arrays of `Backtrace::Location` [Feature #13557] Setting the b..." href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/315bde5a0f95562f58405a43456ec6715ef20d32">git|315bde5a0f95562f58405a43456ec6715ef20d32</a>.</p>
<hr>
<p><code>Exception#set_backtrace</code> accept arrays of <code>Backtrace::Location</code></p>
<p>[Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: there's no way to pass backtrace locations as a massaged backtrace (Closed)" href="https://bugs.ruby-lang.org/issues/13557">#13557</a>]</p>
<p>Setting the backtrace with an array of strings is lossy. The resulting<br>
exception will return nil on <code>#backtrace_locations</code>.</p>
<p>By accepting an array of <code>Backtrace::Location</code> instance, we can rebuild<br>
a <code>Backtrace</code> instance and have a fully functioning Exception.</p>
<p>Co-Authored-By: Étienne Barrié <a href="mailto:etienne.barrie@gmail.com" class="email">etienne.barrie@gmail.com</a></p>