Skip to content

Commit 970e105

Browse files
committed
Improve exception handling, fix pylint errors
1 parent 3c53ca3 commit 970e105

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

check_container_stats_docker.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ def send_socket_cmd(cmd: str, socketfile: str) -> str:
176176
exit_plugin(3, f'Socket file { socketfile } not found!', "")
177177
except PermissionError:
178178
exit_plugin(3, f'Access to socket file { socketfile } denied!', "")
179-
except TimeoutError:
180-
exit_plugin(3, f'Connection to socket { socketfile } timed out!', "")
181-
except socket.timeout:
179+
except (TimeoutError, socket.timeout):
182180
exit_plugin(3, f'Connection to socket { socketfile } timed out!', "")
183181
except ConnectionError as err:
184182
exit_plugin(3, f'Error during socket connection: { err }', "")

check_docker_system.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def send_socket_cmd(cmd: str, socketfile: str) -> str:
102102
exit_plugin(3, f'Socket file { socketfile } not found!', "")
103103
except PermissionError:
104104
exit_plugin(3, f'Access to socket file { socketfile } denied!', "")
105-
except TimeoutError:
105+
except (TimeoutError, socket.timeout):
106106
exit_plugin(3, f'Connection to socket { socketfile } timed out!', "")
107107
except ConnectionError as err:
108108
exit_plugin(3, f'Error during socket connection: { err }', "")
@@ -231,6 +231,9 @@ def convert_bytes_to_pretty(raw_bytes: int):
231231
output = f'{ round(raw_bytes / 1024, 2) }KiB'
232232
elif raw_bytes < 1024:
233233
output = f'{ raw_bytes }B'
234+
else:
235+
# Theoretically impossible, prevent pylint possibly-used-before-assignment
236+
raise ValueError('Impossible value in convert_bytes_to_pretty()')
234237
return output
235238

236239

0 commit comments

Comments
 (0)