diff --git a/jc/parsers/vmstat_s.py b/jc/parsers/vmstat_s.py index e194ab42..77e44562 100644 --- a/jc/parsers/vmstat_s.py +++ b/jc/parsers/vmstat_s.py @@ -74,6 +74,7 @@ Examples: """ import jc.utils from jc.utils import stream_success, stream_error +from jc.exceptions import ParseError class info(): @@ -232,7 +233,10 @@ def parse(data, raw=False, quiet=False, ignore_exceptions=False): 'timezone': tz or None } - yield stream_success(output_line, ignore_exceptions) if raw else stream_success(_process(output_line), ignore_exceptions) + if output_line: + yield stream_success(output_line, ignore_exceptions) if raw else stream_success(_process(output_line), ignore_exceptions) + else: + raise ParseError('Not vmstat data') except Exception as e: yield stream_error(e, ignore_exceptions, line) diff --git a/tests/test_vmstat_s.py b/tests/test_vmstat_s.py index 077b3504..ec14302b 100644 --- a/tests/test_vmstat_s.py +++ b/tests/test_vmstat_s.py @@ -71,7 +71,6 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/vmstat-1-long-streaming.json'), 'r', encoding='utf-8') as f: self.ubuntu_18_04_vmstat_1_long_streaming_json = json.loads(f.read()) - def test_vmstat_nodata(self): """ Test 'vmstat' with no data @@ -81,7 +80,7 @@ class MyTests(unittest.TestCase): def test_vmstat_unparsable(self): data = 'unparsable data' g = jc.parsers.vmstat_s.parse(data.splitlines(), quiet=True) - with self.assertRaises(KeyError): + with self.assertRaises(ParseError): list(g) def test_vmstat_centos_7_7(self):