1# -*- coding: utf-8 -*- 2# Copyright 2010 Google Inc. All Rights Reserved. 3# 4# Permission is hereby granted, free of charge, to any person obtaining a 5# copy of this software and associated documentation files (the 6# "Software"), to deal in the Software without restriction, including 7# without limitation the rights to use, copy, modify, merge, publish, dis- 8# tribute, sublicense, and/or sell copies of the Software, and to permit 9# persons to whom the Software is furnished to do so, subject to the fol- 10# lowing conditions: 11# 12# The above copyright notice and this permission notice shall be included 13# in all copies or substantial portions of the Software. 14# 15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- 17# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 18# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21# IN THE SOFTWARE. 22"""gsutil exceptions. 23 24The exceptions in this module are for use across multiple different classes. 25""" 26 27from __future__ import absolute_import 28 29 30class AbortException(StandardError): 31 """Exception raised when a user aborts a command that needs to do cleanup.""" 32 33 def __init__(self, reason): 34 StandardError.__init__(self) 35 self.reason = reason 36 37 def __repr__(self): 38 return 'AbortException: %s' % self.reason 39 40 def __str__(self): 41 return 'AbortException: %s' % self.reason 42 43 44class CommandException(StandardError): 45 """Exception raised when a problem is encountered running a gsutil command. 46 47 This exception should be used to signal user errors or system failures 48 (like timeouts), not bugs (like an incorrect param value). For the 49 latter you should raise Exception so we can see where/how it happened 50 via gsutil -D (which will include a stack trace for raised Exceptions). 51 """ 52 53 def __init__(self, reason, informational=False): 54 """Instantiate a CommandException. 55 56 Args: 57 reason: Text describing the problem. 58 informational: Indicates reason should be printed as FYI, not a failure. 59 """ 60 StandardError.__init__(self) 61 self.reason = reason 62 self.informational = informational 63 64 def __repr__(self): 65 return str(self) 66 67 def __str__(self): 68 return 'CommandException: %s' % self.reason 69 70 71class HashMismatchException(Exception): 72 """Exception raised when data integrity validation fails.""" 73 pass 74 75 76class InvalidUrlError(Exception): 77 """Exception raised when URL is invalid.""" 78 79 def __init__(self, message): 80 Exception.__init__(self, message) 81 self.message = message 82 83 def __repr__(self): 84 return str(self) 85 86 def __str__(self): 87 return 'InvalidUrlError: %s' % self.message 88