Skip to content

Commit 29ae87d

Browse files
committed
Fail more gracefully when finding module files if no file is specified
Previously this would just complain about trying to call `nil.split`.
1 parent c872619 commit 29ae87d

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/puppet/file_serving/mount/modules.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
class Puppet::FileServing::Mount::Modules < Puppet::FileServing::Mount
66
# Return an instance of the appropriate class.
77
def find(path, request)
8+
raise "No module specified" if path.to_s.empty?
89
module_name, relative_path = path.split("/", 2)
910
return nil unless mod = request.environment.module(module_name)
1011

1112
mod.file(relative_path)
1213
end
1314

1415
def search(path, request)
15-
module_name, relative_path = path.split("/", 2)
16-
return nil unless mod = request.environment.module(module_name)
17-
18-
return nil unless path = mod.file(relative_path)
19-
[path]
16+
if result = find(path, request)
17+
[result]
18+
end
2019
end
2120

2221
def valid?

spec/unit/file_serving/mount/modules_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
end
1313

1414
describe "when finding files" do
15+
it "should fail if no module is specified" do
16+
expect { @mount.find("", @request) }.to raise_error(/No module specified/)
17+
end
18+
1519
it "should use the provided environment to find the module" do
1620
@environment.expects(:module)
1721

@@ -37,6 +41,10 @@
3741
end
3842

3943
describe "when searching for files" do
44+
it "should fail if no module is specified" do
45+
expect { @mount.find("", @request) }.to raise_error(/No module specified/)
46+
end
47+
4048
it "should use the node's environment to search the module" do
4149
@environment.expects(:module)
4250

0 commit comments

Comments
 (0)