@@ -20,78 +20,86 @@ def __init__(self, log: logging.Logger, config: Config) -> None:
2020 self ._log = log
2121 self ._config = config
2222
23- def _log_not_found_info (self , status : cs3status .Status , operation : str , msg : str = None ) -> None :
23+ def _log_not_found_info (self , status : cs3status .Status , operation : str , status_msg : str , msg : str = None ) -> None :
2424 self ._log .info (
2525 f'msg="Not found on { operation } " { msg + " " if msg else "" } '
2626 f'userid="{ self ._config .auth_client_id if self ._config .auth_client_id else "no_id_set" } " '
27- f'trace="{ status .trace } " reason="{ status . message . replace ( '"' , "'" ) } "'
27+ f'trace="{ status .trace } " reason="{ status_msg } "'
2828 )
2929
30- def _log_authentication_error (self , status : cs3status .Status , operation : str , msg : str = None ) -> None :
30+ def _log_authentication_error (
31+ self , status : cs3status .Status , operation : str , status_msg : str , msg : str = None
32+ ) -> None :
3133 self ._log .error (
3234 f'msg="Authentication failed on { operation } " { msg + " " if msg else "" } '
3335 f'userid="{ self ._config .auth_client_id if self ._config .auth_client_id else "no_id_set" } " '
34- f'trace="{ status .trace } " reason="{ status . message . replace ( '"' , "'" ) } "'
36+ f'trace="{ status .trace } " reason="{ status_msg } "'
3537 )
3638
37- def _log_unknown_error (self , status : cs3status .Status , operation : str , msg : str = None ) -> None :
39+ def _log_unknown_error (self , status : cs3status .Status , operation : str , status_msg : str , msg : str = None ) -> None :
3840 self ._log .error (
3941 f'msg="Failed to { operation } , unknown error" { msg + " " if msg else "" } '
4042 f'userid="{ self ._config .auth_client_id if self ._config .auth_client_id else "no_id_set" } " '
41- f'trace="{ status .trace } " reason="{ status . message . replace ( '"' , "'" ) } "'
43+ f'trace="{ status .trace } " reason="{ status_msg } "'
4244 )
4345
44- def _log_precondition_info (self , status : cs3status .Status , operation : str , msg : str = None ) -> None :
46+ def _log_precondition_info (
47+ self , status : cs3status .Status , operation : str , status_msg : str , msg : str = None
48+ ) -> None :
4549 self ._log .info (
4650 f'msg="Failed precondition on { operation } " { msg + " " if msg else "" } '
4751 f'userid="{ self ._config .auth_client_id if self ._config .auth_client_id else "no_id_set" } " '
48- f'trace="{ status .trace } " reason="{ status . message . replace ( '"' , "'" ) } "'
52+ f'trace="{ status .trace } " reason="{ status_msg } "'
4953 )
5054
51- def _log_already_exists (self , status : cs3status .Status , operation : str , msg : str = None ) -> None :
55+ def _log_already_exists (self , status : cs3status .Status , operation : str , status_msg : str , msg : str = None ) -> None :
5256 self ._log .info (
5357 f'msg="Already exists on { operation } " { msg + " " if msg else "" } '
5458 f'userid="{ self ._config .auth_client_id if self ._config .auth_client_id else "no_id_set" } " '
55- f'trace="{ status .trace } " reason="{ status . message . replace ( '"' , "'" ) } "'
59+ f'trace="{ status .trace } " reason="{ status_msg } "'
5660 )
5761
58- def _log_unimplemented (self , status : cs3status .Status , operation : str , msg : str = None ) -> None :
62+ def _log_unimplemented (self , status : cs3status .Status , operation : str , status_msg : str , msg : str = None ) -> None :
5963 self ._log .info (
6064 f'msg="Invoked { operation } on unimplemented feature" { msg + " " if msg else "" } '
6165 f'userid="{ self ._config .auth_client_id if self ._config .auth_client_id else "no_id_set" } " '
62- f'trace="{ status .trace } " reason="{ status . message . replace ( '"' , "'" ) } "'
66+ f'trace="{ status .trace } " reason="{ status_msg } "'
6367 )
6468
6569 def handle_errors (self , status : cs3status .Status , operation : str , msg : str = None ) -> None :
70+
6671 if status .code == cs3code .CODE_OK :
6772 return
73+ # status.message.replace('"', "'") is not allowed inside f strings python<3.12
74+ status_message = status .message .replace ('"' , "'" )
75+
6876 if status .code == cs3code .CODE_FAILED_PRECONDITION or status .code == cs3code .CODE_ABORTED :
69- self ._log_precondition_info (status , operation , msg )
77+ self ._log_precondition_info (status , operation , status_message , msg )
7078 raise FileLockedException (f'Failed precondition: operation="{ operation } " '
7179 f'status_code="{ status .code } " message="{ status .message } "' )
7280 if status .code == cs3code .CODE_ALREADY_EXISTS :
73- self ._log_already_exists (status , operation , msg )
81+ self ._log_already_exists (status , operation , status_message , msg )
7482 raise AlreadyExistsException (f'Resource already exists: operation="{ operation } " '
7583 f'status_code="{ status .code } " message="{ status .message } "' )
7684 if status .code == cs3code .CODE_UNIMPLEMENTED :
7785 self ._log .info (f'msg="Invoked { operation } on unimplemented feature" ' )
7886 raise UnimplementedException (f'Unimplemented feature: operation="{ operation } " '
7987 f'status_code="{ status .code } " message="{ status .message } "' )
8088 if status .code == cs3code .CODE_NOT_FOUND :
81- self ._log_not_found_info (status , operation , msg )
89+ self ._log_not_found_info (status , operation , status_message , msg )
8290 raise NotFoundException (f'Not found: operation="{ operation } " '
8391 f'status_code="{ status .code } " message="{ status .message } "' )
8492 if status .code == cs3code .CODE_UNAUTHENTICATED :
85- self ._log_authentication_error (status , operation , msg )
93+ self ._log_authentication_error (status , operation , status_message , msg )
8694 raise AuthenticationException (f'Operation not permitted: operation="{ operation } " '
8795 f'status_code="{ status .code } " message="{ status .message } "' )
8896 if status .code != cs3code .CODE_OK :
8997 if "path not found" in str (status .message ).lower ():
9098 self ._log .info (f'msg="Invoked { operation } on missing file" ' )
9199 raise NotFoundException (
92100 message = f'No such file or directory: operation="{ operation } " '
93- f'status_code="{ status .code } " message="{ status .message } "'
101+ f'status_code="{ status .code } " message="{ status .message } "'
94102 )
95- self ._log_unknown_error (status , operation , msg )
103+ self ._log_unknown_error (status , operation , status_message , msg )
96104 raise UnknownException (f'Unknown Error: operation="{ operation } " status_code="{ status .code } " '
97105 f'message="{ status .message } "' )
0 commit comments