Skip to content

Commit 2232abd

Browse files
author
Frederick Ross
committed
Unwrapped all HTTPErrors except those being turned into KeyErrors in dict-like contexts.
Removed wrapper exceptions that were no longer used. Fixed the unit tests to expect HTTPErrors.
1 parent fa16dda commit 2232abd

File tree

3 files changed

+10
-45
lines changed

3 files changed

+10
-45
lines changed

splunklib/client.py

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,6 @@
108108

109109
MATCH_ENTRY_CONTENT = "%s/%s/*" % (XNAME_ENTRY, XNAME_CONTENT)
110110

111-
class NoSuchUserException(Exception):
112-
"""Thrown when a request is made to Splunk using a namespace that contains
113-
a nonexistant user."""
114-
pass
115-
116-
class NoSuchApplicationException(Exception):
117-
"""Thrown when a request is made to Splunk using a namespace that contains
118-
a nonexistant application."""
119-
pass
120-
121111
class IllegalOperationException(Exception):
122112
"""Thrown when an operation is not possible on the Splunk instance that a
123113
:class:`Service` object is connected to."""
@@ -142,11 +132,6 @@ class InvalidNameException(Exception):
142132
in Splunk entity names."""
143133
pass
144134

145-
class OperationFailedException(Exception):
146-
"""Thrown when the requested operation resulted in an error in Splunk (and a
147-
400 HTTP return status)."""
148-
pass
149-
150135
class NoSuchCapability(Exception):
151136
"""Thrown when the capability that has been referred to doesn't exist."""
152137
pass
@@ -2403,13 +2388,7 @@ def oneshot(self, path, **kwargs):
24032388
available parameters, see `Input parameters <http://dev.splunk.com/view/SP-CAAAEE6#inputparams>`_ on Splunk Developer Portal.
24042389
:type kwargs: ``dict``
24052390
"""
2406-
try:
2407-
self.post('oneshot', name=path, **kwargs)
2408-
except HTTPError as he:
2409-
if he.status == 400:
2410-
raise OperationFailedException(str(he))
2411-
else:
2412-
raise
2391+
self.post('oneshot', name=path, **kwargs)
24132392

24142393

24152394
class Job(Entity):
@@ -2779,11 +2758,7 @@ def create(self, query, **kwargs):
27792758
"""
27802759
if kwargs.get("exec_mode", None) == "oneshot":
27812760
raise TypeError("Cannot specify exec_mode=oneshot; use the oneshot method instead.")
2782-
try:
2783-
response = self.post(search=query, **kwargs)
2784-
except HTTPError as he:
2785-
if he.status == 400: # Bad request. Raise a TypeError with the reason.
2786-
raise TypeError(str(he))
2761+
response = self.post(search=query, **kwargs)
27872762
sid = _load_sid(response)
27882763
return Job(self.service, sid)
27892764

@@ -2820,13 +2795,7 @@ def export(self, query, **params):
28202795
"""
28212796
if "exec_mode" in params:
28222797
raise TypeError("Cannot specify an exec_mode to export.")
2823-
try:
2824-
return self.post(path_segment="export", search=query, **params).body
2825-
except HTTPError as he:
2826-
if he.status == 400:
2827-
raise ValueError(str(he))
2828-
else:
2829-
raise
2798+
return self.post(path_segment="export", search=query, **params).body
28302799

28312800
def itemmeta(self):
28322801
"""There is no metadata available for class:``Jobs``.
@@ -2883,13 +2852,8 @@ def oneshot(self, query, **params):
28832852
"""
28842853
if "exec_mode" in params:
28852854
raise TypeError("Cannot specify an exec_mode to oneshot.")
2886-
try:
2887-
return self.post(search=query, exec_mode="oneshot", **params).body
2888-
except HTTPError as he:
2889-
if he.status == 400:
2890-
raise ValueError(str(he))
2891-
else:
2892-
raise
2855+
return self.post(search=query, exec_mode="oneshot", **params).body
2856+
28932857

28942858
class Loggers(Collection):
28952859
"""This class represents a collection of service logging categories.

tests/test_input.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1414
# License for the specific language governing permissions and limitations
1515
# under the License.
16+
from splunklib.binding import HTTPError
1617

1718
import testlib
1819
import logging
@@ -196,7 +197,7 @@ def f():
196197

197198
def test_oneshot_on_nonexistant_file(self):
198199
name = testlib.tmpname()
199-
self.assertRaises(client.OperationFailedException,
200+
self.assertRaises(HTTPError,
200201
self.service.inputs.oneshot, name)
201202

202203
class TestInput(testlib.SDKTestCase):

tests/test_job.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_oneshot(self):
5050

5151
def test_export_with_garbage_fails(self):
5252
jobs = self.service.jobs
53-
self.assertRaises(ValueError, jobs.export, "asdaf;lkj2r23=")
53+
self.assertRaises(client.HTTPError, jobs.export, "asdaf;lkj2r23=")
5454

5555
def test_export(self):
5656
jobs = self.service.jobs
@@ -68,8 +68,8 @@ def test_normal_job_with_garbage_fails(self):
6868
try:
6969
bad_search = "abcd|asfwqqq"
7070
jobs.create(bad_search)
71-
except TypeError as te:
72-
self.assertTrue('abcd' in str(te))
71+
except client.HTTPError as he:
72+
self.assertTrue('abcd' in str(he))
7373
return
7474
self.fail("Job with garbage search failed to raise TypeError.")
7575

0 commit comments

Comments
 (0)