ruby/psych

Parsing aliases `aliases: false` should not raise `Psych::BadAlias`

amomchilov opened this issue · 2 comments

Simple minimal example:

#!/usr/bin/ruby

require "yaml"

yaml_with_aliases = <<~YAML
---
a: &ABC
  k1: v1
  k2: v2
b: *ABC
YAML

p YAML.load(yaml_with_aliases)

This raises an error: Unknown alias: ABC (Psych::BadAlias)

Raising an error in this case sense, but I think Psych::BadAlias is an incorrect error type. It communicates an incorrect impression that the issue is with the structure of the YAML, not the configuration of the YAML/Psych. The message makes it even worse.

Perhaps there should be a more specific error type, like Psych::AliasParsingDisabled. The message could then mention that if you want anchors/aliases to work, that you should passes aliases: true.

Thoughts?

Adding a specific exception for this case makes sense. Can you submit a patch for it?

Sure! I just wanted to make sure it's a desirable behaviour before implementing it.

I'll probably take a stab at it some time next week.