Skip to content

Commit 2e58734

Browse files
committed
Added exception to handle json parsing error
1 parent a12f8c1 commit 2e58734

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

SoftLayer/CLI/order/place.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ def cli(env, package_keyname, location, preset, verify, billing, complex_type,
7676
manager = ordering.OrderingManager(env.client)
7777

7878
if extras:
79-
extras = json.loads(extras)
79+
try:
80+
extras = json.loads(extras)
81+
except ValueError as err:
82+
raise exceptions.CLIAbort("There was an error when parsing the --extras value: {}".format(err.message))
8083

8184
args = (package_keyname, location, order_items)
8285
kwargs = {'preset_keyname': preset,

SoftLayer/CLI/order/place_quote.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import click
77

88
from SoftLayer.CLI import environment
9+
from SoftLayer.CLI import exceptions
910
from SoftLayer.CLI import formatting
1011
from SoftLayer.managers import ordering
1112

@@ -68,7 +69,10 @@ def cli(env, package_keyname, location, preset, name, send_email, complex_type,
6869
manager = ordering.OrderingManager(env.client)
6970

7071
if extras:
71-
extras = json.loads(extras)
72+
try:
73+
extras = json.loads(extras)
74+
except ValueError as err:
75+
raise exceptions.CLIAbort("There was an error when parsing the --extras value: {}".format(err.message))
7276

7377
args = (package_keyname, location, order_items)
7478
kwargs = {'preset_keyname': preset,

tests/CLI/modules/order_tests.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77

88
from SoftLayer import testing
9+
from SoftLayer.CLI import exceptions
910

1011

1112
class OrderTests(testing.TestCase):
@@ -103,6 +104,13 @@ def test_place(self):
103104
'status': 'APPROVED'},
104105
json.loads(result.output))
105106

107+
def test_place_extras_parameter_fail(self):
108+
result = self.run_command(['-y', 'order', 'place', 'package', 'DALLAS13', 'ITEM1',
109+
'--extras', '{"device":['])
110+
111+
self.assertEqual(result.exit_code, 2)
112+
self.assertIsInstance(result.exception, exceptions.CLIAbort)
113+
106114
def test_place_quote(self):
107115
order_date = '2018-04-04 07:39:20'
108116
expiration_date = '2018-05-04 07:39:20'
@@ -132,6 +140,13 @@ def test_place_quote(self):
132140
'status': 'PENDING'},
133141
json.loads(result.output))
134142

143+
def test_place_quote_extras_parameter_fail(self):
144+
result = self.run_command(['-y', 'order', 'place-quote', 'package', 'DALLAS13', 'ITEM1',
145+
'--extras', '{"device":['])
146+
147+
self.assertEqual(result.exit_code, 2)
148+
self.assertIsInstance(result.exception, exceptions.CLIAbort)
149+
135150
def test_verify_hourly(self):
136151
order_date = '2017-04-04 07:39:20'
137152
order = {'orderId': 1234, 'orderDate': order_date,

0 commit comments

Comments
 (0)