Skip to content

Commit

Permalink
Raise ModuleNotFound if a module is not found
Browse files Browse the repository at this point in the history
While 026e0c1 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.
  • Loading branch information
ekohl committed Apr 28, 2023
1 parent 6a9aecd commit a216455
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/puppet_forge/v3/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions spec/unit/forge/v3/module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit a216455

Please sign in to comment.