Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/linux_admin/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ def run(cmd, options = {})
error ||= ""
self.exitstatus = nil
end

rescue Errno::ENOENT => err
raise NoSuchFileError.new(err.message) if NoSuchFileError.detected?(err.message)
raise
else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest trimming up the whitespace on lines 27 and 31

CommandResult.new(output, error, status)
end

Expand Down
10 changes: 10 additions & 0 deletions lib/linux_admin/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ def initialize(message, result)
end

class LinuxAdmin
class NoSuchFileError < Errno::ENOENT
def initialize(message)
super(message.split("No such file or directory -").last.split(" ").first)
end

def self.detected?(message)
message.start_with?("No such file or directory -")
end
end

class CredentialError < CommandResultError
def initialize(result)
super("Invalid username or password", result)
Expand Down
2 changes: 1 addition & 1 deletion spec/common_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class TestClass
end

it "command bad" do
expect {subject.send(run_method, "XXXXX")}.to raise_error(Errno::ENOENT)
expect {subject.send(run_method, "XXXXX --user=bob")}.to raise_error(LinuxAdmin::NoSuchFileError, "No such file or directory - XXXXX")
end

context "#exit_status" do
Expand Down