Commit 2f60ab6
committed
Catch OSError exceptions
If a user passes a socket file that does not exist then the
is_unix_socket will raise an exception :
➜ haproxytool acl -F /var/lib/haproxy/statss -s /etc/haproxy/block_traffic_header_names.list
Traceback (most recent call last):
File "/home/pavlos/.virtualenvs/haproxy/bin/haproxytool", line 8, in <module>
sys.exit(main())
File "/home/pavlos/.virtualenvs/haproxy/lib/python3.9/site-packages/haproxytool/cli.py", line 41, in main
call_main(sub_cmd)
File "/home/pavlos/.virtualenvs/haproxy/lib/python3.9/site-packages/haproxytool/acl.py", line 107, in main
hap = haproxy_object(arguments)
File "/home/pavlos/.virtualenvs/haproxy/lib/python3.9/site-packages/haproxytool/utils.py", line 57, in haproxy_object
hap = haproxy.HAProxy(socket_file=arguments['--file'],
File "/home/pavlos/.virtualenvs/haproxy/lib/python3.9/site-packages/haproxyadmin/haproxy.py", line 117, in __init__
elif (socket_file and is_unix_socket(socket_file) and
File "/home/pavlos/.virtualenvs/haproxy/lib/python3.9/site-packages/haproxyadmin/utils.py", line 157, in is_unix_socket
mode = os.stat(path).st_mode
FileNotFoundError: [Errno 2] No such file or directory: '/var/lib/haproxy/statss'
Let's avoid this situation by catching OSError class exceptions.1 parent 1edd49a commit 2f60ab6
1 file changed
+4
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
158 | 161 | | |
159 | 162 | | |
160 | 163 | | |
| |||
0 commit comments