summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-11-30 09:15:51 -0600
committerSamuel Giddins <segiddins@segiddins.me>2016-11-30 09:15:51 -0600
commitb77e96f6db444534cf69013c8e8b0346e88b76d1 (patch)
tree1accc28c5838c68f52bbf54f3c4459450a5c9d4c
parentb567a9130b38ea1c65c93eef879edd54ae386596 (diff)
downloadbundler-b77e96f6db444534cf69013c8e8b0346e88b76d1.tar.gz
[SharedHelpers] Handle generic SystemCallErrors in #filesystem_access
-rw-r--r--lib/bundler/errors.rb20
-rw-r--r--lib/bundler/shared_helpers.rb4
-rw-r--r--spec/bundler/shared_helpers_spec.rb21
3 files changed, 45 insertions, 0 deletions
diff --git a/lib/bundler/errors.rb b/lib/bundler/errors.rb
index dd5782fb3d..be72a9ee47 100644
--- a/lib/bundler/errors.rb
+++ b/lib/bundler/errors.rb
@@ -132,4 +132,24 @@ module Bundler
status_code(28)
end
+
+ class NoSpaceOnDeviceError < PermissionError
+ def message
+ "There was an error while trying to #{action} `#{@path}`. " \
+ "There was insufficent space remaining on the device."
+ end
+
+ status_code(31)
+ end
+
+ class GenericSystemCallError < BundlerError
+ attr_reader :underlying_error
+
+ def initialize(underlying_error, message)
+ @underlying_error = underlying_error
+ super("#{message}\nThe underlying system error is #{@underlying_error.class}: #{@underlying_error}")
+ end
+
+ status_code(32)
+ end
end
diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb
index 0ddcea1ca5..f7806ce1d6 100644
--- a/lib/bundler/shared_helpers.rb
+++ b/lib/bundler/shared_helpers.rb
@@ -111,8 +111,12 @@ module Bundler
raise TemporaryResourceError.new(path, action)
rescue Errno::EPROTO
raise VirtualProtocolError.new
+ rescue Errno::ENOSPC
+ raise NoSpaceOnDeviceError.new(path, action)
rescue *[const_get_safely(:ENOTSUP, Errno)].compact
raise OperationNotSupportedError.new(path, action)
+ rescue SystemCallError => e
+ raise GenericSystemCallError.new(e, "There was an error accessing `#{path}`.")
end
def const_get_safely(constant_name, namespace)
diff --git a/spec/bundler/shared_helpers_spec.rb b/spec/bundler/shared_helpers_spec.rb
index 8826dcd4dd..fc3371acfb 100644
--- a/spec/bundler/shared_helpers_spec.rb
+++ b/spec/bundler/shared_helpers_spec.rb
@@ -388,6 +388,27 @@ describe Bundler::SharedHelpers do
)
end
end
+
+ context "system throws Errno::ENOSPC" do
+ let(:file_op_block) { proc {|_path| raise Errno::ENOSPC } }
+
+ it "raises a NoSpaceOnDeviceError" do
+ expect { subject.filesystem_access("/path", &file_op_block) }.to raise_error(
+ Bundler::NoSpaceOnDeviceError
+ )
+ end
+ end
+
+ context "system throws an unhandled SystemCallError" do
+ let(:error) { SystemCallError.new("Shields down", 1337) }
+ let(:file_op_block) { proc {|_path| raise error } }
+
+ it "raises a GenericSystemCallError" do
+ expect { subject.filesystem_access("/path", &file_op_block) }.to raise_error(
+ Bundler::GenericSystemCallError, /error accessing.+underlying.+Shields down/m
+ )
+ end
+ end
end
describe "#const_get_safely" do