summaryrefslogtreecommitdiff
path: root/ext/psych/lib/psych
diff options
context:
space:
mode:
authorAlexander Momchilov <alexander.momchilov@shopify.com>2022-07-22 16:16:04 -0400
committergit <svn-admin@ruby-lang.org>2022-08-09 01:33:34 +0900
commit9c13a6ce5ff1f83489d9df65a5c7745efe16c8a4 (patch)
tree2c4a80f1addbe2b8ba1538752bb844ca89d4b3e7 /ext/psych/lib/psych
parent4b9cdf4e1cbb87c4f81edef472c586cd321e924e (diff)
[ruby/psych] Raise specific error when an anchor isn't defined
https://github.com/ruby/psych/commit/98fbd5247a
Diffstat (limited to 'ext/psych/lib/psych')
-rw-r--r--ext/psych/lib/psych/exception.rb7
-rw-r--r--ext/psych/lib/psych/visitors/to_ruby.rb2
2 files changed, 8 insertions, 1 deletions
diff --git a/ext/psych/lib/psych/exception.rb b/ext/psych/lib/psych/exception.rb
index 04a9a906a4..d7469a4b30 100644
--- a/ext/psych/lib/psych/exception.rb
+++ b/ext/psych/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/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb
index 0bf5198ccc..cce5daf3bb 100644
--- a/ext/psych/lib/psych/visitors/to_ruby.rb
+++ b/ext/psych/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