summaryrefslogtreecommitdiff
path: root/ext/psych
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-22 01:26:40 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-22 01:26:40 +0000
commit8dd3a4af668cd92245af86206371d3d2e9619571 (patch)
tree1f617dfc6f151f32528b463789b93645d74c487f /ext/psych
parent0331314d278d0590ff26eb7ec156f859b590464f (diff)
* ext/psych/parser.c (parse): add the file name to the exception when
parse errors occur. * test/psych/test_parser.rb: test for parse error file name git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30626 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/psych')
-rw-r--r--ext/psych/parser.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/ext/psych/parser.c b/ext/psych/parser.c
index 5a9d2c75f9..7bfdf4af90 100644
--- a/ext/psych/parser.c
+++ b/ext/psych/parser.c
@@ -4,6 +4,7 @@ VALUE cPsychParser;
VALUE ePsychSyntaxError;
static ID id_read;
+static ID id_path;
static ID id_empty;
static ID id_start_stream;
static ID id_end_stream;
@@ -93,13 +94,20 @@ static VALUE parse(VALUE self, VALUE yaml)
while(!done) {
if(!yaml_parser_parse(parser, &event)) {
+ VALUE path;
size_t line = parser->mark.line;
size_t column = parser->mark.column;
+ if(rb_respond_to(yaml, id_path))
+ path = rb_funcall(yaml, id_path, 0);
+ else
+ path = rb_str_new2("<unknown>");
+
yaml_parser_delete(parser);
yaml_parser_initialize(parser);
- rb_raise(ePsychSyntaxError, "couldn't parse YAML at line %d column %d",
+ rb_raise(ePsychSyntaxError, "(%s): couldn't parse YAML at line %d column %d",
+ StringValuePtr(path),
(int)line, (int)column);
}
@@ -360,6 +368,7 @@ void Init_psych_parser()
rb_define_method(cPsychParser, "external_encoding=", set_external_encoding, 1);
id_read = rb_intern("read");
+ id_path = rb_intern("path");
id_empty = rb_intern("empty");
id_start_stream = rb_intern("start_stream");
id_end_stream = rb_intern("end_stream");