Skip to content

Commit bbd54cc

Browse files
author
Juliya Smith
committed
Catch all socket errors
1 parent 0164892 commit bbd54cc

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

c42seceventcli/aed/main.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from socket import gaierror
2+
from socket import error as socket_error
33
from urllib3 import disable_warnings
44
from urllib3.exceptions import InsecureRequestWarning
55
from datetime import datetime, timedelta
@@ -89,17 +89,17 @@ def _get_logger(
8989
destination_port=destination_port,
9090
destination_protocol=destination_protocol,
9191
)
92-
except gaierror:
93-
args.cli_parser.print_usage()
92+
except socket_error as ex:
93+
print(repr(ex))
9494
print(
95-
"Error with provided server destination arguments: hostname={0}, port={1}, protocol={2}.".format(
95+
"Hostname={0}, port={1}, protocol={2}.".format(
9696
destination, destination_port, destination_protocol
9797
)
9898
)
9999
exit(1)
100-
except IOError:
101-
args.cli_parser.print_usage()
102-
print("Error with provided file path {0}. Try --dest path/to/file.".format(destination))
100+
except IOError as ex:
101+
print(repr(ex))
102+
print("File path: {0}.".format(destination))
103103
exit(1)
104104

105105

tests/aed/test_args.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,18 @@ def test_get_args_calls_sec_args_try_set_with_expected_args(
8484
mock_setter.assert_called_once_with(key, expected_cli_val, expected_config_val)
8585

8686

87-
def test_get_args_when_destination_is_not_none_and_destination_type_is_stdout_raises_value_error(patches):
87+
def test_get_args_when_destination_is_not_none_and_destination_type_is_stdout_raises_value_error(
88+
patches
89+
):
8890
patches.cli_args.destination_type = "stdout"
8991
patches.cli_args.destination = "Delaware"
9092
with pytest.raises(ValueError):
9193
get_args()
9294

9395

94-
def test_get_args_when_destination_is_none_and_destination_type_is_server_raises_value_error(patches):
96+
def test_get_args_when_destination_is_none_and_destination_type_is_server_raises_value_error(
97+
patches
98+
):
9599
patches.cli_args.destination_type = "server"
96100
patches.cli_args.destination = None
97101
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)