diff --git a/Library/Homebrew/macos_version.rb b/Library/Homebrew/macos_version.rb index 988e1621cb..0d40d22735 100644 --- a/Library/Homebrew/macos_version.rb +++ b/Library/Homebrew/macos_version.rb @@ -139,9 +139,23 @@ end require "lazy_object" -MacOSVersionError = LazyObject.new do # rubocop:disable Style/MutableConstant - # odeprecated "MacOSVersionError", "MacOSVersion::Error" - MacOSVersion::Error +# `LazyObject` does not work for exceptions when used in `rescue` statements. +class Object + class << self + module MacOSVersionErrorCompat + def const_missing(name) + if name == :MacOSVersionError + # odeprecated "MacOSVersionError", "MacOSVersion::Error" + return MacOSVersion::Error + end + + super + end + end + private_constant :MacOSVersionErrorCompat + + prepend MacOSVersionErrorCompat + end end module MacOSVersions