Skip to content

Commit 448c3ad

Browse files
(FM-8643) Ensure library requires fail usefully
This commit places the requires statement for the ruby-pwsh ruby code (found in the dependency module, puppetlabs-pwshlib) in a begin-rescue block and adds a loud error message that points at the solution. This will cause the loading of the providers to still fail during autoloading, but to do so usefully. We chose not to use the feature/confine pattern because it is not supported by the resource_api, the primary interface through which we expect community members to write types and providers in the future. We chose not to use a utility loader method, which would have prevented breaking during autoloading, because of the friction and additional complexity cost incurred for every module needing to adopt this pattern. While this rescued-requires pattern will still cause an error during autoloading, this should only be possible in cases where the module is being installed from github and the dependency chain is not installed.
1 parent 9dea688 commit 448c3ad

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

.rubocop_todo.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2019-10-18 11:01:56 -0500 using RuboCop version 0.49.1.
3+
# on 2019-10-30 10:31:01 -0500 using RuboCop version 0.49.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 4
9+
# Offense count: 6
1010
GetText/DecorateFunctionMessage:
1111
Exclude:
1212
- 'lib/puppet/provider/exec/powershell.rb'
1313
- 'lib/puppet/provider/exec/pwsh.rb'
1414
- 'spec/spec_helper_acceptance.rb'
1515

16-
# Offense count: 1
16+
# Offense count: 3
1717
GetText/DecorateString:
1818
Exclude:
1919
- 'lib/puppet/provider/exec/powershell.rb'
20+
- 'lib/puppet/provider/exec/pwsh.rb'

lib/puppet/provider/exec/powershell.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
require 'puppet/provider/exec'
2-
require 'ruby-pwsh'
2+
begin
3+
require 'ruby-pwsh'
4+
rescue LoadError
5+
raise 'Could not load the "ruby-pwsh" library; is the dependency module puppetlabs-pwshlib installed in this environment?'
6+
end
37

48
Puppet::Type.type(:exec).provide :powershell, :parent => Puppet::Provider::Exec do
59
confine :operatingsystem => :windows

lib/puppet/provider/exec/pwsh.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
require 'puppet/provider/exec'
2-
require 'ruby-pwsh'
2+
begin
3+
require 'ruby-pwsh'
4+
rescue LoadError
5+
raise 'Could not load the "ruby-pwsh" library; is the dependency module puppetlabs-pwshlib installed in this environment?'
6+
end
37

48
Puppet::Type.type(:exec).provide :pwsh, :parent => Puppet::Provider::Exec do
59
desc <<-EOT

0 commit comments

Comments
 (0)