From 6425157eae086f3c50c7055a936daab4647d6090 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Mon, 9 Mar 2026 15:31:07 +0900 Subject: [ruby/rubygems] Simplify Psych exception stubs and fallback raises https://github.com/ruby/rubygems/commit/61bfb3fff8 --- lib/rubygems/yaml_serializer.rb | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/lib/rubygems/yaml_serializer.rb b/lib/rubygems/yaml_serializer.rb index 72207c7c53..28616cdfde 100644 --- a/lib/rubygems/yaml_serializer.rb +++ b/lib/rubygems/yaml_serializer.rb @@ -1,27 +1,12 @@ # frozen_string_literal: true -unless defined?(Psych::Exception) - begin - require "psych/exception" - rescue LoadError - module Psych - class Exception < ::RuntimeError; end - class SyntaxError < Exception; end - - class DisallowedClass < Exception - def initialize(action, klass_name) - super("Tried to #{action} unspecified class: #{klass_name}") - end - end - - class BadAlias < Exception; end - - class AliasesNotEnabled < BadAlias - def initialize - super "Alias parsing was not enabled. To enable it, pass `aliases: true` to `Psych::load` or `Psych::safe_load`." - end - end - end +unless defined?(Psych::VERSION) + module Psych + class Exception < ::RuntimeError; end + class SyntaxError < Exception; end + class DisallowedClass < Exception; end + class BadAlias < Exception; end + class AliasesNotEnabled < BadAlias; end end end @@ -582,13 +567,21 @@ module Gem def validate_tag!(tag) unless @permitted_tags.include?(tag) - raise Psych::DisallowedClass.new("load", tag) + if defined?(Psych::VERSION) + raise Psych::DisallowedClass.new("load", tag) + else + raise Psych::DisallowedClass, "Tried to load unspecified class: #{tag}" + end end end def validate_symbol!(sym) if @permitted_symbols.any? && !@permitted_symbols.include?(sym.to_s) - raise Psych::DisallowedClass.new("load", sym.inspect) + if defined?(Psych::VERSION) + raise Psych::DisallowedClass.new("load", sym.inspect) + else + raise Psych::DisallowedClass, "Tried to load unspecified class: #{sym.inspect}" + end end end -- cgit v1.2.3