Skip to content

Commit 508c8fc

Browse files
committed
Standardized error messages
1 parent 4e539b2 commit 508c8fc

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

cs3client/exceptions/exceptions.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
exceptions.py
33
44
Custom exception classes for the CS3 client.
5+
Where applicable, the default values correspond to the Linux standard error strings.
56
67
Authors: Rasmus Welander, Diogo Castro, Giuseppe Lo Presti.
78
@@ -14,7 +15,7 @@ class AuthenticationException(Exception):
1415
Standard error thrown when attempting an operation without the required access rights
1516
"""
1617

17-
def __init__(self, message: str = ""):
18+
def __init__(self, message: str = "Operation not permitted"):
1819
super().__init__(message)
1920

2021

@@ -23,7 +24,7 @@ class NotFoundException(IOError):
2324
Standard file missing message
2425
"""
2526

26-
def __init__(self, message: str = ""):
27+
def __init__(self, message: str = "No such file or directory"):
2728
super().__init__(message)
2829

2930

@@ -32,7 +33,7 @@ class SecretNotSetException(Exception):
3233
Standard file missing message
3334
"""
3435

35-
def __init__(self, message: str = ""):
36+
def __init__(self, message: str = "Secret was not set, unable to authenticate"):
3637
super().__init__(message)
3738

3839

@@ -42,7 +43,7 @@ class FileLockedException(IOError):
4243
or when a lock operation cannot be performed because of failed preconditions
4344
"""
4445

45-
def __init__(self, message: str = ""):
46+
def __init__(self, message: str = "Lock mismatch"):
4647
super().__init__(message)
4748

4849

@@ -60,7 +61,7 @@ class AlreadyExistsException(IOError):
6061
Standard error thrown when attempting to create a resource that already exists
6162
"""
6263

63-
def __init__(self, message: str = ""):
64+
def __init__(self, message: str = "File exists"):
6465
super().__init__(message)
6566

6667

@@ -69,5 +70,5 @@ class UnimplementedException(Exception):
6970
Standard error thrown when attempting to use a feature that is not implemented
7071
"""
7172

72-
def __init__(self, message: str = ""):
73+
def __init__(self, message: str = "Not implemented"):
7374
super().__init__(message)

cs3client/statuscodehandler.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,31 +75,23 @@ def handle_errors(self, status: cs3status.Status, operation: str, msg: str = Non
7575

7676
if status.code == cs3code.CODE_FAILED_PRECONDITION or status.code == cs3code.CODE_ABORTED:
7777
self._log_precondition_info(status, operation, status_message, msg)
78-
raise FileLockedException(f'Failed precondition: operation="{operation}" '
79-
f'status_code="{status.code}" message="{status.message}"')
78+
raise FileLockedException
8079
if status.code == cs3code.CODE_ALREADY_EXISTS:
8180
self._log_already_exists(status, operation, status_message, msg)
82-
raise AlreadyExistsException(f'Resource already exists: operation="{operation}" '
83-
f'status_code="{status.code}" message="{status.message}"')
81+
raise AlreadyExistsException
8482
if status.code == cs3code.CODE_UNIMPLEMENTED:
8583
self._log.info(f'msg="Invoked {operation} on unimplemented feature" ')
86-
raise UnimplementedException(f'Unimplemented feature: operation="{operation}" '
87-
f'status_code="{status.code}" message="{status.message}"')
84+
raise UnimplementedException
8885
if status.code == cs3code.CODE_NOT_FOUND:
8986
self._log_not_found_info(status, operation, status_message, msg)
90-
raise NotFoundException(f'Not found: operation="{operation}" '
91-
f'status_code="{status.code}" message="{status.message}"')
87+
raise NotFoundException
9288
if status.code == cs3code.CODE_UNAUTHENTICATED:
9389
self._log_authentication_error(status, operation, status_message, msg)
94-
raise AuthenticationException(f'Operation not permitted: operation="{operation}" '
95-
f'status_code="{status.code}" message="{status.message}"')
90+
raise AuthenticationException
9691
if status.code != cs3code.CODE_OK:
9792
if "path not found" in str(status.message).lower():
9893
self._log.info(f'msg="Invoked {operation} on missing file" ')
99-
raise NotFoundException(
100-
message=f'No such file or directory: operation="{operation}" '
101-
f'status_code="{status.code}" message="{status.message}"'
102-
)
94+
raise NotFoundException
10395
self._log_unknown_error(status, operation, status_message, msg)
10496
raise UnknownException(f'Unknown Error: operation="{operation}" status_code="{status.code}" '
10597
f'message="{status.message}"')

0 commit comments

Comments
 (0)