|
| 1 | +""" |
| 2 | +exceptions |
| 3 | +
|
| 4 | +Custom exception classes for the CS3 client. |
| 5 | +Where applicable, the default values correspond to the Linux standard error strings. |
| 6 | +
|
| 7 | +Authors: Rasmus Welander, Diogo Castro, Giuseppe Lo Presti. |
| 8 | + |
| 9 | +Last updated: 01/08/2024 |
| 10 | +""" |
| 11 | + |
| 12 | + |
| 13 | +class AuthenticationException(Exception): |
| 14 | + """ |
| 15 | + Standard error thrown when attempting an operation without the required access rights |
| 16 | + """ |
| 17 | + |
| 18 | + def __init__(self, message: str = "Operation not permitted"): |
| 19 | + super().__init__(message) |
| 20 | + |
| 21 | + |
| 22 | +class NotFoundException(IOError): |
| 23 | + """ |
| 24 | + Standard file missing message |
| 25 | + """ |
| 26 | + |
| 27 | + def __init__(self, message: str = "No such file or directory"): |
| 28 | + super().__init__(message) |
| 29 | + |
| 30 | + |
| 31 | +class SecretNotSetException(Exception): |
| 32 | + """ |
| 33 | + Standard file missing message |
| 34 | + """ |
| 35 | + |
| 36 | + def __init__(self, message: str = "Secret was not set, unable to authenticate"): |
| 37 | + super().__init__(message) |
| 38 | + |
| 39 | + |
| 40 | +class FileLockedException(IOError): |
| 41 | + """ |
| 42 | + Standard error thrown when attempting to overwrite a file/xattr with a mistmatched lock, |
| 43 | + or when a lock operation cannot be performed because of failed preconditions |
| 44 | + """ |
| 45 | + |
| 46 | + def __init__(self, message: str = "Lock mismatch"): |
| 47 | + super().__init__(message) |
| 48 | + |
| 49 | + |
| 50 | +class UnknownException(Exception): |
| 51 | + """ |
| 52 | + Standard exception to be thrown when we get an error that is unknown, e.g. not defined in the cs3api |
| 53 | + """ |
| 54 | + |
| 55 | + def __init__(self, message: str = ""): |
| 56 | + super().__init__(message) |
| 57 | + |
| 58 | + |
| 59 | +class AlreadyExistsException(IOError): |
| 60 | + """ |
| 61 | + Standard error thrown when attempting to create a resource that already exists |
| 62 | + """ |
| 63 | + |
| 64 | + def __init__(self, message: str = "File exists"): |
| 65 | + super().__init__(message) |
| 66 | + |
| 67 | + |
| 68 | +class UnimplementedException(Exception): |
| 69 | + """ |
| 70 | + Standard error thrown when attempting to use a feature that is not implemented |
| 71 | + """ |
| 72 | + |
| 73 | + def __init__(self, message: str = "Not implemented"): |
| 74 | + super().__init__(message) |
0 commit comments