Skip to content

Commit

Permalink
Throw SFTP::Error when Bash process started by Shell fails
Browse files Browse the repository at this point in the history
  • Loading branch information
ssciolla committed Mar 18, 2024
1 parent bf22dd9 commit 4ff7df7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/sftp/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module Shell
def self.run(array_of_commands)
command_str = [array_of_commands].join(" ")
`bash -c \"#{command_str}\"`
return if $CHILD_STATUS.success?

raise Error, "Error occurred during SFTP process: #{$CHILD_STATUS.exitstatus}"
end
end
end
12 changes: 12 additions & 0 deletions spec/sftp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,15 @@
end
end
end

RSpec.describe SFTP::Shell do
before(:each) do
@shell = SFTP::Shell
end

context "#run" do
it "throws Error when run fails" do
expect { @shell.run ["gobbledegook"] }.to raise_error(SFTP::Error)
end
end
end

0 comments on commit 4ff7df7

Please sign in to comment.