diff options
| author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2026-03-09 15:31:07 +0900 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2026-03-09 07:59:46 +0000 |
| commit | 6425157eae086f3c50c7055a936daab4647d6090 (patch) | |
| tree | 53074a8a8669585b7d359f2a9beb352a14ae2b7b | |
| parent | 6a92781ff6b4a4338aaf26cf79fbf9f0f20dc382 (diff) | |
[ruby/rubygems] Simplify Psych exception stubs and fallback raises
https://github.com/ruby/rubygems/commit/61bfb3fff8
| -rw-r--r-- | lib/rubygems/yaml_serializer.rb | 41 |
1 files 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 |
