mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/psych] Raise specific error when an anchor isn't defined
https://github.com/ruby/psych/commit/98fbd5247a
This commit is contained in:
parent
4b9cdf4e1c
commit
9c13a6ce5f
4 changed files with 10 additions and 3 deletions
|
@ -13,6 +13,13 @@ module Psych
|
|||
end
|
||||
end
|
||||
|
||||
# Subclasses `BadAlias` for backwards compatibility
|
||||
class AnchorNotDefined < BadAlias
|
||||
def initialize anchor_name
|
||||
super "An alias referenced an unknown anchor: #{anchor_name}"
|
||||
end
|
||||
end
|
||||
|
||||
class DisallowedClass < Exception
|
||||
def initialize action, klass_name
|
||||
super "Tried to #{action} unspecified class: #{klass_name}"
|
||||
|
|
|
@ -323,7 +323,7 @@ module Psych
|
|||
end
|
||||
|
||||
def visit_Psych_Nodes_Alias o
|
||||
@st.fetch(o.anchor) { raise BadAlias, "Unknown alias: #{o.anchor}" }
|
||||
@st.fetch(o.anchor) { raise AnchorNotDefined, o.anchor }
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -124,7 +124,7 @@ module Psych
|
|||
end
|
||||
|
||||
def test_raises_if_anchor_not_defined
|
||||
assert_raise(Psych::BadAlias) do
|
||||
assert_raise(Psych::AnchorNotDefined) do
|
||||
Psych.unsafe_load(<<~eoyml)
|
||||
---
|
||||
foo: &foo
|
||||
|
|
|
@ -117,7 +117,7 @@ development:
|
|||
bar:
|
||||
<< : *foo
|
||||
eoyml
|
||||
exp = assert_raise(Psych::BadAlias) { Psych.load(yaml, aliases: true) }
|
||||
exp = assert_raise(Psych::AnchorNotDefined) { Psych.load(yaml, aliases: true) }
|
||||
assert_match 'foo', exp.message
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue