Project

General

Profile

Actions

Bug #1248

closed

e.exception(e) returns self

Added by tmat (Tomas Matousek) over 16 years ago. Updated about 14 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.0 (2007-12-25 revision 14709) [i386-mswin32]
Backport:
[ruby-core:22687]

Description

=begin
Exception#exception(arg) instance method should return a new exception of the same class as self with message arg. It does so for any object passed in as an argument except for if e is passed in. I don't see any reason for special casing the method this way.

Repro:
e = Exception.new
p e.exception(e).object_id == e.object_id # => true; it should return false
=end

Actions #1

Updated by matz (Yukihiro Matsumoto) over 16 years ago

=begin
Hi,

In message "Re: [ruby-core:22687] [Bug #1248] e.exception(e) returns self"
on Fri, 6 Mar 2009 04:36:56 +0900, Tomas Matousek writes:

|Exception#exception(arg) instance method should return a new exception of the same class as self with message arg. It does so for any object passed in as an argument except for if e is passed in. I don't see any reason for special casing the method this way.
|
|Repro:
|e = Exception.new
|p e.exception(e).object_id == e.object_id # => true; it should return false

You've missed the reason why you considered this behavior to be a bug.
Have you been bitten by this? Or just for the sake of your feeling of
consistency? Avoiding object allocation is one good reason.

						matz.

=end

Actions #2

Updated by tmat (Tomas Matousek) over 16 years ago

=begin
Well the reason is that arg is supposed to be a message, right? A message can be an arbitrary object. So if I pass e as a message, why it doesn't become a value of the message property?

irb(main):001:0> a = Exception.new
=> #<Exception: Exception>
irb(main):002:0> b = Exception.new
=> #<Exception: Exception>
irb(main):003:0> c = a.exception(b)
=> #<Exception: #Exception:0x31f1d34> # this is ok, b is now a message of c
irb(main):004:0> c.message == b
=> true
irb(main):005:0> c = a.exception(a)
=> #<Exception: Exception>
irb(main):006:0> c.message == a # a is not a message of c
=> false
irb(main):007:0> c == a # instead, c is a
=> true

It's not about saving an allocation. It's that for all objects, except for self, the method sets a message on a new exception object. Only for self it doesn't. (at least as far as I observe)

Tomas

-----Original Message-----
From: Yukihiro Matsumoto []
Sent: Thursday, March 05, 2009 10:55 PM
To:
Subject: [ruby-core:22696] Re: [Bug #1248] e.exception(e) returns self

Hi,

In message "Re: [ruby-core:22687] [Bug #1248] e.exception(e) returns self"
on Fri, 6 Mar 2009 04:36:56 +0900, Tomas Matousek writes:

|Exception#exception(arg) instance method should return a new exception of the same class as self with message arg. It does so for any object passed in as an argument except for if e is passed in. I don't see any reason for special casing the method this way.
|
|Repro:
|e = Exception.new
|p e.exception(e).object_id == e.object_id # => true; it should return false

You've missed the reason why you considered this behavior to be a bug.
Have you been bitten by this? Or just for the sake of your feeling of
consistency? Avoiding object allocation is one good reason.

						matz.

=end

Actions #3

Updated by matz (Yukihiro Matsumoto) over 16 years ago

=begin
Hi,

In message "Re: [ruby-core:22698] Re: [Bug #1248] e.exception(e) returns self"
on Fri, 6 Mar 2009 16:52:47 +0900, Tomas Matousek writes:

|Well the reason is that arg is supposed to be a message, right? A message can be an arbitrary object. So if I pass e as a message, why it doesn't become a value of the message property?

The arg is supposed to be an exception, or exception class, or a
message, which means arg is a message only when arg is a string. The
whole purpose of exception method is to duck-type raise semantics,
that is

raise ExceptionClass # specifying exception class

to make a new exception, and

raise anException # specifying exception object

to re-raise the exception.

						matz.

=end

Actions #4

Updated by tmat (Tomas Matousek) over 16 years ago

=begin
What should be the result of calling x.exception(Exception arg) and x.exception(Class arg) then? Currently both create a new exception of type x.class with message arg (unless arg == x).

  1. Passing a class:

irb(main):001:0> a = Exception.new
=> #<Exception: Exception>
irb(main):002:0> b = a.exception(IOError)
=> #<Exception: #Exception:0x3127bc4>
irb(main):003:0> b.message
=> IOError
irb(main):004:0> b.message.class
=> Class

  1. Passing an exception instance:

irb(main):001:0> a = Exception.new
=> #<Exception: Exception>
irb(main):002:0> b = a.exception(IOError.new)
=> #<Exception: #Exception:0x33e701c>
irb(main):003:0> b.message
=> #<IOError: IOError>

  1. Passing a string:

irb(main):001:0> a = Exception.new
=> #<Exception: Exception>
irb(main):002:0> b = a.exception("some message")
=> #<Exception: some message>
irb(main):003:0> b.message
=> "some message"

Hence "arg is a message only when arg is a string" is not true for the current implementation.
I'm not saying that cases 1) and 2) are wrong. There are correct in some sense (unless message is intended to always be a string). The case that's definitely broken is

irb(main):001:0> a = Exception.new
=> #<Exception: Exception>
irb(main):002:0> a.exception(a)
=> #<Exception: Exception>

Tomas

-----Original Message-----
From: Yukihiro Matsumoto []
Sent: Friday, March 06, 2009 12:44 AM
To:
Subject: [ruby-core:22699] Re: [Bug #1248] e.exception(e) returns self

Hi,

In message "Re: [ruby-core:22698] Re: [Bug #1248] e.exception(e) returns self"
on Fri, 6 Mar 2009 16:52:47 +0900, Tomas Matousek writes:

|Well the reason is that arg is supposed to be a message, right? A message can be an arbitrary object. So if I pass e as a message, why it doesn't become a value of the message property?

The arg is supposed to be an exception, or exception class, or a
message, which means arg is a message only when arg is a string. The
whole purpose of exception method is to duck-type raise semantics,
that is

raise ExceptionClass # specifying exception class

to make a new exception, and

raise anException # specifying exception object

to re-raise the exception.

						matz.

=end

Actions #5

Updated by tmat (Tomas Matousek) over 16 years ago

=begin
What's the status of Unicode/culture-sensitive operations in Ruby 1.9.1?

I tried following:

encoding: UTF-8

str = "combining mark: a\u{30a}";
p str.index("\u{e5}")

=> nil

The result should be 16.

["a", "b", "c", "d", "e", "\u{e9}" "\u{e1}"].sort.each { |x| print x.dump, " " }

=> "a" "b" "c" "d" "e" "\u{e1}" "\u{e9}"

The correct result is:

"a" "\u{e1}" "b" "c" "d" "e" "\u{e9}"

So it seems that string operations such as sort, index, etc. work on a binary representation of the strings (correct me please, if I am wrong), not taking Unicode properties of the characters into consideration. Also does (will) Ruby have notion of culture (used to collate etc.)?

Tomas

=end

Actions #6

Updated by matz (Yukihiro Matsumoto) over 16 years ago

=begin
Hi,

In message "Re: [ruby-core:22784] Unicode sensitive operations"
on Tue, 10 Mar 2009 02:59:56 +0900, Tomas Matousek writes:

|What's the status of Unicode/culture-sensitive operations in Ruby 1.9.1?

Currently the string comparison is done by byte-by-byte. The
culture-sensitive operation should be done by external libraries, such
as unicode.

						matz.

=end

Actions #7

Updated by yugui (Yuki Sonoda) almost 16 years ago

  • Status changed from Open to Rejected

=begin
Can I reject the issue?
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0