diff --git a/ChangeLog b/ChangeLog index 6b74ad12b6..2fa0142f87 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Tue Oct 23 06:21:05 2012 Aaron Patterson + + * ext/psych/parser.c: just get the constant defined in Ruby. + + * ext/psych/lib/psych/syntax_error.rb: Psych::SyntaxError now inherits + from StandardError rather than SyntaxError. Thanks Eric Hodel! + + * test/psych/test_exception.rb: tests for change. + Tue Oct 23 06:17:36 2012 Aaron Patterson * ext/psych/lib/psych/scalar_scanner.rb: Cache symbols while diff --git a/ext/psych/lib/psych/syntax_error.rb b/ext/psych/lib/psych/syntax_error.rb index f79743dba4..f972256f9e 100644 --- a/ext/psych/lib/psych/syntax_error.rb +++ b/ext/psych/lib/psych/syntax_error.rb @@ -1,5 +1,8 @@ module Psych - class SyntaxError < ::SyntaxError + class Error < RuntimeError + end + + class SyntaxError < Error attr_reader :file, :line, :column, :offset, :problem, :context def initialize file, line, col, offset, problem, context diff --git a/ext/psych/parser.c b/ext/psych/parser.c index 0908a1b49f..8c65ce1307 100644 --- a/ext/psych/parser.c +++ b/ext/psych/parser.c @@ -557,7 +557,7 @@ void Init_psych_parser() rb_define_const(cPsychParser, "UTF16BE", INT2NUM(YAML_UTF16BE_ENCODING)); rb_require("psych/syntax_error"); - ePsychSyntaxError = rb_define_class_under(mPsych, "SyntaxError", rb_eSyntaxError); + ePsychSyntaxError = rb_const_get(mPsych, rb_intern("SyntaxError")); rb_define_method(cPsychParser, "parse", parse, -1); rb_define_method(cPsychParser, "mark", mark, 0); diff --git a/test/psych/test_exception.rb b/test/psych/test_exception.rb index c6d98d7a99..5615fc2db4 100644 --- a/test/psych/test_exception.rb +++ b/test/psych/test_exception.rb @@ -126,5 +126,26 @@ module Psych assert_equal 1, w.foo assert_nil w.bar end + + def test_psych_syntax_error + Tempfile.open(['parsefile', 'yml']) do |t| + t.binmode + t.write '--- `' + t.close + + begin + Psych.parse_file t.path + rescue StandardError + assert true # count assertion + ensure + return unless $! + + ancestors = $!.class.ancestors.inspect + + flunk "Psych::SyntaxError not rescued by StandardError: #{ancestors}" + end + end + end + end end