psych icon indicating copy to clipboard operation
psych copied to clipboard

BadAlias error message doesn't include filename

Open gdb opened this issue 11 years ago • 2 comments

Parse errors from YAML.load_file will include the filename, which is useful in case you're e.g. parsing a number of configuration files:

File.write('/tmp/file.yaml', "\tfoo:"); YAML.load_file('/tmp/file.yaml')
#=> Psych::SyntaxError: (/tmp/file.yaml): found character that cannot start any token while scanning for the next token at line 1 column 1

However, errors with alias resolution will not:

File.write('/tmp/file.yaml', "foo: *bar"); YAML.load_file('/tmp/file.yaml')
#=> Psych::BadAlias: Unknown alias: bar

Is there any obvious way to tag that exception with the relevant filename, if applicable? It doesn't appear that the parsed document retains a reference to the filename, which probably makes this trickier.

gdb avatar May 26 '14 17:05 gdb

We could probably add the origin filename to the AST produced by parsing the YAML file, then we could include the filename in the exception. However, line number info might be prohibitively expensive.

tenderlove avatar May 28 '14 21:05 tenderlove

Yeah, that would be totally fine for my use-case. (We have a bunch of YAML config files, and given a file and missing alias it's quite easy to go and fix it.)

gdb avatar May 28 '14 21:05 gdb