From a216455506c6af405c817f4505334f768764a6fd Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Fri, 28 Apr 2023 13:08:51 +0200 Subject: [PATCH] Raise ModuleNotFound if a module is not found While 026e0c1f467a6edc1e40d3827840fe3b123bef66 did add the exception class, it wasn't used. This avoids leaking an implementation detail. Technically this is backwards incompatible, since it requires users to change their code. It could make PuppetForge::ModuleNotFound inherit from Faraday::ResourceNotFound, but that stil leaks the implementation detail. --- lib/puppet_forge/v3/module.rb | 5 +++++ spec/unit/forge/v3/module_spec.rb | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/puppet_forge/v3/module.rb b/lib/puppet_forge/v3/module.rb index 5d35ac3..b3b6d39 100644 --- a/lib/puppet_forge/v3/module.rb +++ b/lib/puppet_forge/v3/module.rb @@ -11,6 +11,11 @@ class Module < Base lazy :current_release, 'Release' lazy_collection :releases, 'Release' + def self.find(slug) + super + rescue Faraday::ResourceNotFound + raise PuppetForge::ModuleNotFound, "Module #{slug} not found" + end end end end diff --git a/spec/unit/forge/v3/module_spec.rb b/spec/unit/forge/v3/module_spec.rb index a228349..231e434 100644 --- a/spec/unit/forge/v3/module_spec.rb +++ b/spec/unit/forge/v3/module_spec.rb @@ -28,8 +28,8 @@ expect(mod_stateless.name).to eq('apache') end - it 'returns nil for non-existent modules' do - expect { missing_mod }.to raise_error(Faraday::ResourceNotFound) + it 'raises exception for non-existent modules' do + expect { missing_mod }.to raise_error(PuppetForge::ModuleNotFound, 'Module absent-apache not found') end end