-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Psych can't load a dumped Exception that contains a NameError::message class #85
Comments
The page is not accessible at the moment; you can find it here |
As a reference: I think I am using libyaml, and I have the same issue. The only difference is that calling |
Calling |
Calling For now, I'm probably going to resort to something extremely hacky like using a regex to see if the YAML dump contains |
In my Rails app, I've added a method to Psych that special-cases the encoding of NameErrors:
This could be done more cleanly in Psych itself (a single |
* master: (21 commits) * ext/psych/lib/psych/visitors/to_ruby.rb: call `allocate` on hash subclasses. Fixes github.com//issues/196 * ext/psych/lib/psych/visitors/to_ruby.rb: revive hashes with ivars removed isolate task removed isolate plugin added minitest dependency into gemspec added install task into travis added ruby-head env bumping version to 2.0.8 fixed build error caused by trunk changes bumping version to 2.0.7 merging from ruby trunk backport r48512 from ruby/ruby trunk. Add changelog for 2a4d956 backport r48214 from ruby/ruby trunk. Allow dumping any BasicObject that defines #marshal_dump or #marshal_load bumping version * ext/psych/lib/psych/visitors/yaml_tree.rb: fix NameError dumping and loading. Fixes GH #85. Thanks @brentdax for the patch! * test/psych/test_exception.rb: test for fix * ext/psych/lib/psych/scalar_scanner.rb: fix loading strings that look like integers but have a newline. Fixes GH #189 * test/psych/test_string.rb: test for fix * ext/psych/lib/psych/visitors/to_ruby.rb: merge keys with a hash should merge the hash in to the parent. * test/psych/test_merge_keys.rb: test for change. Fixes GH #202 * ext/psych/lib/psych/visitors/to_ruby.rb: quoted "<<" strings should not be treated as merge keys. * ext/psych/lib/psych/visitors/yaml_tree.rb: hashes with keys containing "<<" should roundtrip. * test/psych/test_merge_keys.rb: test for change. Fixes GH #203 ... Conflicts: lib/psych/visitors/yaml_tree.rb
Psych can't load a dumped Exception that contains a NameError::message class. Here is a test showing this.
This fails with "TypeError: allocator undefined for NameError::message"
NoMethodError's internal message is not a String but a special class called NameError::message. The message string itself is delayed until called. Once .message is called, the internal NameError::message goes away and you're left with a String. If you try to dump/load a NoMethodError after .message (or .inspect, or .to_s) has been called, then it will work properly. The way to make it fail is to call it without having called .message, as the test above does. Note that if you try the above in irb, as separate lines, it will appear to work, because irb calls .inspect after the first line, and thus .message is called.
When dumping the NoMethodError without having called .message (like the test), the dump looks like this:
When dumping the NoMethodError after having called .message, the dump looks like this:
I never knew about NameError::message, but I learned a lot about it from this link: http://www.carboni.ca/blog/p/Ruby-Did-You-Know-That-5-NameErrormessage
The text was updated successfully, but these errors were encountered: