ruby / ruby/psych

BadAlias error message doesn't include filename

Open
#192 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
597
Forks
223
Avg merge
11h 23m
Merged PRs (30d)
3

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two YAML.load_file examples in the issue and compare the filename handling for Psych::SyntaxError and Psych::BadAlias. Trace how the parsed document and alias-resolution error are created; done means an applicable BadAlias reports the relevant filename without changing the existing alias message.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.