@@ -20,78 +20,86 @@ def __init__(self, log: logging.Logger, config: Config) -> None:
20
20
self ._log = log
21
21
self ._config = config
22
22
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 :
24
24
self ._log .info (
25
25
f'msg="Not found on { operation } " { msg + " " if msg else "" } '
26
26
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 } "'
28
28
)
29
29
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 :
31
33
self ._log .error (
32
34
f'msg="Authentication failed on { operation } " { msg + " " if msg else "" } '
33
35
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 } "'
35
37
)
36
38
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 :
38
40
self ._log .error (
39
41
f'msg="Failed to { operation } , unknown error" { msg + " " if msg else "" } '
40
42
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 } "'
42
44
)
43
45
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 :
45
49
self ._log .info (
46
50
f'msg="Failed precondition on { operation } " { msg + " " if msg else "" } '
47
51
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 } "'
49
53
)
50
54
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 :
52
56
self ._log .info (
53
57
f'msg="Already exists on { operation } " { msg + " " if msg else "" } '
54
58
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 } "'
56
60
)
57
61
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 :
59
63
self ._log .info (
60
64
f'msg="Invoked { operation } on unimplemented feature" { msg + " " if msg else "" } '
61
65
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 } "'
63
67
)
64
68
65
69
def handle_errors (self , status : cs3status .Status , operation : str , msg : str = None ) -> None :
70
+
66
71
if status .code == cs3code .CODE_OK :
67
72
return
73
+ # status.message.replace('"', "'") is not allowed inside f strings python<3.12
74
+ status_message = status .message .replace ('"' , "'" )
75
+
68
76
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 )
70
78
raise FileLockedException (f'Failed precondition: operation="{ operation } " '
71
79
f'status_code="{ status .code } " message="{ status .message } "' )
72
80
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 )
74
82
raise AlreadyExistsException (f'Resource already exists: operation="{ operation } " '
75
83
f'status_code="{ status .code } " message="{ status .message } "' )
76
84
if status .code == cs3code .CODE_UNIMPLEMENTED :
77
85
self ._log .info (f'msg="Invoked { operation } on unimplemented feature" ' )
78
86
raise UnimplementedException (f'Unimplemented feature: operation="{ operation } " '
79
87
f'status_code="{ status .code } " message="{ status .message } "' )
80
88
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 )
82
90
raise NotFoundException (f'Not found: operation="{ operation } " '
83
91
f'status_code="{ status .code } " message="{ status .message } "' )
84
92
if status .code == cs3code .CODE_UNAUTHENTICATED :
85
- self ._log_authentication_error (status , operation , msg )
93
+ self ._log_authentication_error (status , operation , status_message , msg )
86
94
raise AuthenticationException (f'Operation not permitted: operation="{ operation } " '
87
95
f'status_code="{ status .code } " message="{ status .message } "' )
88
96
if status .code != cs3code .CODE_OK :
89
97
if "path not found" in str (status .message ).lower ():
90
98
self ._log .info (f'msg="Invoked { operation } on missing file" ' )
91
99
raise NotFoundException (
92
100
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 } "'
94
102
)
95
- self ._log_unknown_error (status , operation , msg )
103
+ self ._log_unknown_error (status , operation , status_message , msg )
96
104
raise UnknownException (f'Unknown Error: operation="{ operation } " status_code="{ status .code } " '
97
105
f'message="{ status .message } "' )
0 commit comments