Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fix bug that causes YAML serialization problem for Exception. #41

Closed
wants to merge 1 commit into from

3 participants

Jingwen Owen Ou Urabe, Shyouhei Nobuyoshi Nakada
Jingwen Owen Ou

The implementation of YAML.object_maker allocates an object and
instance_variable_set the instance variables passed as the second
argument, while Exception doesn't seem to use such instance variable to
return the exception message (Exception#message). This bug can be
reproduced by typing
YAML::load(YAML::dump(Exception.new('test_message'))) in IRB, e.g.,

ruby-1.9.2-p290 :001 > require 'yaml'
=> true
ruby-1.9.2-p290 :002 > YAML::load(YAML::dump(Exception.new('test_message')))
=> #<Exception: Exception>

#<Exception: "test_message"> is expected while the result is #<Exception: Exception>.

Jingwen Owen Ou jingweno Fix bug that causes YAML serialization problem for Exception.
The implementation of YAML.object_maker allocates an object and
instance_variable_set the instance variables passed as the second
argument, while Exception doesn't seem to use such instance variable to
return the exception message (Exception#message). This bug can be
reproduced by typing
YAML::load(YAML::dump(Exception.new('test_message'))) in IRB.
f0d970c
Jingwen Owen Ou

The problem is related to Exception#message not being correctly un-serialized. This bug can be reproduced with executing:

YAML::load(YAML::dump(Exception.new('test_message')))

I proposed a fix. Please take a look.

Urabe, Shyouhei
Owner

(comment) This doesn't happen with Psych.

Jingwen Owen Ou

But some popular gems such as delayed_job (https://github.com/collectiveidea/delayed_job/blob/master/lib/delayed/yaml_ext.rb) are still depending on syck. What's the road map for syck? Is Psych going to replace syck? Why are there two implementations for YAML serialization?

Urabe, Shyouhei
Owner

Hey, I just pointed out the fact. Nothing more. This can still be pulled.

However if you want a concrete road map of syck this is not the place for it. Please move to http://redmine.ruby-lang.org/projects/ruby-19/issues/new .

Jingwen Owen Ou

Oh...I was just trying to understand whether this is a real bug or not, your comment kinda confused me. Thanks for the clarification :). Hope this one will be fixed in the next Ruby release :).

Jingwen Owen Ou

Hi, can I confirm that this bug has been recognized and close the pull request? Thanks

Jingwen Owen Ou

Since I haven't got response till now, I created a bug report: http://redmine.ruby-lang.org/issues/5415

Nobuyoshi Nakada
Collaborator

Applied at r34908.

Nobuyoshi Nakada nobu closed this
Jingwen Owen Ou

Thanks @nobu!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 10, 2011
  1. Jingwen Owen Ou

    Fix bug that causes YAML serialization problem for Exception.

    jingweno authored
    The implementation of YAML.object_maker allocates an object and
    instance_variable_set the instance variables passed as the second
    argument, while Exception doesn't seem to use such instance variable to
    return the exception message (Exception#message). This bug can be
    reproduced by typing
    YAML::load(YAML::dump(Exception.new('test_message'))) in IRB.
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 2 deletions.
  1. +4 1 ext/syck/lib/syck/rubytypes.rb
  2. +1 1  test/syck/test_exception.rb
5 ext/syck/lib/syck/rubytypes.rb
View
@@ -122,7 +122,10 @@ def to_yaml( opts = {} )
class Exception
yaml_as "tag:ruby.yaml.org,2002:exception"
def Exception.yaml_new( klass, tag, val )
- o = YAML.object_maker( klass, { 'mesg' => val.delete( 'message' ) } )
+ o = klass.allocate
+ Exception.instance_method(:initialize).
+ bind(o).
+ call( val.delete( 'message' ) )
val.each_pair do |k,v|
o.instance_variable_set("@#{k}", v)
end
2  test/syck/test_exception.rb
View
@@ -13,7 +13,7 @@ def initialize *args
end
def setup
- @wups = Wups.new
+ @wups = Wups.new('test_message')
end
def test_to_yaml
Something went wrong with that request. Please try again.