Project

General

Profile

Actions

Feature #6286

closed

Add Exception#format method

Added by vo.x (Vit Ondruch) about 12 years ago. Updated almost 5 years ago.

Status:
Closed
Target version:
-
[ruby-core:44328]

Description

It would be nice if Exception class could be extended by #format method (or method with some more suitable name), which would provide the same formatting as is standard output of Ruby exception, e.g.

boomtest.rb:18:in go': boom (RuntimeError) from boomtest.rb:34:in foo'
from boomtest.rb:36

Currently, this formatting is done by error_print function from eval_error.c. Unfortunately this method is just Ruby's internal.

Please note that there exists exception_string gem, which add similar method [1] to the Exception class.

[1] https://github.com/raggi/exception_string/blob/master/lib/exception_string.rb#L15-19


Files

0001-Feature-6286.patch (11.5 KB) 0001-Feature-6286.patch nobu (Nobuyoshi Nakada), 04/16/2012 08:57 PM
Actions #1

Updated by nobu (Nobuyoshi Nakada) about 12 years ago

  • Tracker changed from Bug to Feature

Updated by nobu (Nobuyoshi Nakada) about 12 years ago

  • Tracker changed from Feature to Bug
  • Category set to lib
  • Status changed from Open to Feedback
  • Target version set to 2.0.0

vo.x (Vit Ondruch) wrote:

It would be nice if Exception class could be extended by #format method (or method with some more suitable name), which would provide the same formatting as is standard output of Ruby exception, e.g.

Why and how would it be nice?

Updated by vo.x (Vit Ondruch) about 12 years ago

  • ruby -v set to ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]

nobu (Nobuyoshi Nakada) wrote:

Why and how would it be nice?

I'm trying to develop Ruby support for ABRT [1]. The idea is, that I will provide at_exit handler and in this handler, I need to report the backtrace. I'd like to report the same backtrace as Ruby reports when running from command line. Since the Exception cannot provide this format, I need to provide some custom functionality to get the backtrace formatted as Ruby does.

I am probably not the first one who needs it, otherwise the gem would not exist.

Thank you.

[1] https://fedorahosted.org/abrt/

Updated by vo.x (Vit Ondruch) about 12 years ago

It is actually surprising that the formatting of exception is not provided by the Exception class. I realise that it is probably due to some historic reasons, but once the Exception has its #format method, it could be used in place of error_print().

Actions #5

Updated by nobu (Nobuyoshi Nakada) about 12 years ago

  • Tracker changed from Bug to Feature

Updated by nobu (Nobuyoshi Nakada) about 12 years ago

Yet I'm not sure whether it's worth, made a patch.

Updated by vo.x (Vit Ondruch) almost 12 years ago

Would it be possible to make the #format method public? And if I may be a bit daring, some documentation would be nice. I appreciate your effort. Thank you.

Updated by ko1 (Koichi Sasada) over 11 years ago

  • Status changed from Feedback to Assigned
  • Assignee set to mame (Yusuke Endoh)

mame-san, could you check it?

Updated by mame (Yusuke Endoh) over 11 years ago

  • Assignee changed from mame (Yusuke Endoh) to matz (Yukihiro Matsumoto)
  • Target version changed from 2.0.0 to 2.6

ko1 (Koichi Sasada) wrote:

mame-san, could you check it?

Looks too specific to include it in core...
At least, it is not a urgent need, I think.

--
Yusuke Endoh

Updated by vo.x (Vit Ondruch) over 6 years ago

I would still love to see this accepted.

Updated by Eregon (Benoit Daloze) over 6 years ago

Isn't this a duplicate of #14141?

Actions #12

Updated by naruse (Yui NARUSE) over 6 years ago

  • Target version deleted (2.6)
Actions #13

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

  • Tracker changed from Bug to Feature
  • Status changed from Assigned to Closed
  • ruby -v deleted (-)
  • Backport deleted (2.3: UNKNOWN, 2.4: UNKNOWN)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0