Skip to content
Closed
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
21 changes: 21 additions & 0 deletions S3/Exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from Utils import getTreeFromXml, unicodise, deunicodise
from logging import debug, info, warning, error
import ExitCodes

try:
import xml.etree.ElementTree as ET
Expand Down Expand Up @@ -64,6 +65,26 @@ def __unicode__(self):
retval += (u": %s" % self.info["Message"])
return retval

def get_error_code(self):
if self.status in [301, 307]:
return ExitCodes.EX_SERVERMOVED
elif self.status in [400, 405, 411, 416, 501]:
return ExitCodes.EX_SERVERERROR
elif self.status == 403:
return ExitCodes.EX_ACCESSDENIED
elif self.status == 404:
return ExitCodes.EX_NOTFOUND
elif self.status == 409:
return ExitCodes.EX_CONFLICT
elif self.status == 412:
return ExitCodes.EX_PRECONDITION
elif self.status == 500:
return ExitCodes.EX_SOFTWARE
elif self.status == 503:
return ExitCodes.EX_SERVICE
else:
return ExitCodes.EX_SOFTWARE

@staticmethod
def parse_error_xml(tree):
info = {}
Expand Down
34 changes: 20 additions & 14 deletions S3/ExitCodes.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# patterned on /usr/include/sysexits.h

EX_OK = 0
EX_GENERAL = 1
EX_SOMEFAILED = 2 # some parts of the command succeeded, while others failed
EX_USAGE = 64 # The command was used incorrectly (e.g. bad command line syntax)
EX_SOFTWARE = 70 # internal software error (e.g. S3 error of unknown specificity)
EX_OSERR = 71 # system error (e.g. out of memory)
EX_OSFILE = 72 # OS error (e.g. invalid Python version)
EX_IOERR = 74 # An error occurred while doing I/O on some file.
EX_TEMPFAIL = 75 # temporary failure (S3DownloadError or similar, retry later)
EX_NOPERM = 77 # Insufficient permissions to perform the operation on S3
EX_CONFIG = 78 # Configuration file error
_EX_SIGNAL = 128
_EX_SIGINT = 2
EX_BREAK = _EX_SIGNAL + _EX_SIGINT # Control-C (KeyboardInterrupt raised)
EX_OK = 0
EX_GENERAL = 1
EX_PARTIAL = 2 # some parts of the command succeeded, while others failed
EX_SERVERMOVED = 10 # 301: Moved permanantly & 307: Moved temp
EX_SERVERERROR = 11 # 400, 405, 411, 416, 501: Bad request
EX_NOTFOUND = 12 # 404: Not found
EX_CONFLICT = 13 # 409: Conflict (ex: bucket error)
EX_PRECONDITION = 14 # 412: Precondition failed
EX_SERVICE = 15 # 503: Service not available or slow down
EX_USAGE = 64 # The command was used incorrectly (e.g. bad command line syntax)
EX_SOFTWARE = 70 # internal software error (e.g. S3 error of unknown specificity)
EX_OSERR = 71 # system error (e.g. out of memory)
EX_OSFILE = 72 # OS error (e.g. invalid Python version)
EX_IOERR = 74 # An error occurred while doing I/O on some file.
EX_TEMPFAIL = 75 # temporary failure (S3DownloadError or similar, retry later)
EX_ACCESSDENIED = 77 # Insufficient permissions to perform the operation on S3
EX_CONFIG = 78 # Configuration file error
_EX_SIGNAL = 128
_EX_SIGINT = 2
EX_BREAK = _EX_SIGNAL + _EX_SIGINT # Control-C (KeyboardInterrupt raised)
18 changes: 9 additions & 9 deletions s3cmd
Original file line number Diff line number Diff line change
Expand Up @@ -2435,14 +2435,10 @@ def main():
error(u"Not enough parameters for command '%s'" % command)
sys.exit(EX_USAGE)

try:
rc = cmd_func(args)
if rc is None: # if we missed any cmd_*() returns
rc = EX_GENERAL
return rc
except S3Error, e:
error(u"S3 error: %s" % e)
sys.exit(EX_SOFTWARE)
rc = cmd_func(args)
if rc is None: # if we missed any cmd_*() returns
rc = EX_GENERAL
return rc

def report_exception(e, msg=''):
sys.stderr.write(u"""
Expand Down Expand Up @@ -2533,7 +2529,11 @@ if __name__ == '__main__':
error(u"S3 Temporary Error: %s. Please try again later." % e)
sys.exit(EX_TEMPFAIL)

except (S3Error, S3Exception, S3ResponseError, CloudFrontError), e:
except S3Error, e:
error(u"S3 error: %s" % e)
sys.exit(e.get_error_code())

except (S3Exception, S3ResponseError, CloudFrontError), e:
report_exception(e)
sys.exit(EX_SOFTWARE)

Expand Down