Skip to content

Commit

Permalink
(FM-7696) remove overzealous exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidS committed Jan 24, 2019
1 parent b6cbdcf commit 4a1ce11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
10 changes: 3 additions & 7 deletions lib/puppet/resource_api/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ def register(schema)

def connect(name, connection_info)
validate(name, connection_info)
begin
require "puppet/transport/#{name}"
class_name = name.split('_').map { |e| e.capitalize }.join
Puppet::Transport.const_get(class_name).new(connection_info)
rescue LoadError, NameError => detail
raise Puppet::DevError, 'Cannot load transport for `%{target}`: %{detail}' % { target: name, detail: detail }
end
require "puppet/transport/#{name}"
class_name = name.split('_').map { |e| e.capitalize }.join
Puppet::Transport.const_get(class_name).new(connection_info)
end
module_function :connect # rubocop:disable Style/AccessModifierDeclarations

Expand Down
5 changes: 2 additions & 3 deletions spec/puppet/resource_api/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@
context 'when the transport file does not exist' do
it 'throws a DevError' do
expect(described_class).to receive(:validate).with(name, connection_info)
expect { described_class.connect(name, connection_info) }.to raise_error Puppet::DevError,
%r{Cannot load transport for `test_target`}
expect { described_class.connect(name, connection_info) }.to raise_error LoadError, %r{(no such file to load|cannot load such file) -- puppet/transport/test_target}
end
end

Expand All @@ -114,7 +113,7 @@
it 'throws a DevError' do
expect(described_class).to receive(:validate).with(name, connection_info)
expect(described_class).to receive(:require).with('puppet/transport/test_target')
expect { described_class.connect(name, connection_info) }.to raise_error Puppet::DevError,
expect { described_class.connect(name, connection_info) }.to raise_error NameError,
%r{uninitialized constant (Puppet::Transport|TestTarget)}
end
end
Expand Down

0 comments on commit 4a1ce11

Please sign in to comment.