summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlexander Momchilov <alexander.momchilov@shopify.com>2022-07-22 16:16:04 -0400
committerAlexander Momchilov <alexander.momchilov@shopify.com>2022-07-27 15:25:26 -0400
commit98fbd5247a1727230ec3c0d459d24fd07f5d2bd4 (patch)
treea0c33f3581527a7a207a303e66eb4fd71081b5ee /lib
parent42b43de997f9c19dbd9f204f4399c02e74a4bf03 (diff)
downloadpsych-98fbd5247a1727230ec3c0d459d24fd07f5d2bd4.tar.gz
Raise specific error when an anchor isn't defined
Diffstat (limited to 'lib')
-rw-r--r--lib/psych/exception.rb7
-rw-r--r--lib/psych/visitors/to_ruby.rb2
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/psych/exception.rb b/lib/psych/exception.rb
index 04a9a90..d7469a4 100644
--- a/lib/psych/exception.rb
+++ b/lib/psych/exception.rb
@@ -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}"
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb
index 0bf5198..cce5daf 100644
--- a/lib/psych/visitors/to_ruby.rb
+++ b/lib/psych/visitors/to_ruby.rb
@@ -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