diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-10-04 17:53:41 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-10-04 17:53:41 +0000 |
commit | 137c547c3ef8167630170275ba2ae5a14fa0af95 (patch) | |
tree | 6faa8acdcfe3ac9f79b33cca6b9e5971903ace9e /ext/psych/lib/psych/syntax_error.rb | |
parent | 77e58a3398cde8a0e9b0cb07ffe20e6137efe41c (diff) |
* ext/psych/lib/psych/syntax_error.rb: Add file, line, offset, and
message attributes during parse failure.
* ext/psych/parser.c: Update parser to raise exception with correct
values.
* test/psych/test_exception.rb: corresponding tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33404 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/psych/lib/psych/syntax_error.rb')
-rw-r--r-- | ext/psych/lib/psych/syntax_error.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ext/psych/lib/psych/syntax_error.rb b/ext/psych/lib/psych/syntax_error.rb new file mode 100644 index 0000000000..9fe3e0da30 --- /dev/null +++ b/ext/psych/lib/psych/syntax_error.rb @@ -0,0 +1,18 @@ +module Psych + class SyntaxError < ::SyntaxError + attr_reader :file, :line, :column, :offset, :problem, :context + + def initialize file, line, col, offset, problem, context + err = [problem, context].compact.join ' ' + message = "(%s): %s at line %d column %d" % [file, err, line, col] + + @file = file + @line = line + @column = col + @offset = offset + @problem = problem + @context = context + super(message) + end + end +end |