From b5ede905a4471a8239883c4ec3cc03fba8ec686e Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 16 Mar 2024 11:44:08 +0100 Subject: Handle JSON decode errors when processing events. Seems nftrace events produce non-JSON data even with nft -j. --- naros.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/naros.py b/naros.py index a77cd7f..0e38563 100755 --- a/naros.py +++ b/naros.py @@ -653,7 +653,13 @@ class NftMonitor: def process(self, process_cb): for line in self._child.stdout: - cmd, val = nft_json_pop(json.loads(line)) + try: + data = json.loads(line) + except json.decoder.JSONDecodeError: + self._logger.error('Error decoding event: %s', line) + continue + + cmd, val = nft_json_pop(data) self._logger.debug('Nft event: %s %s', cmd, val) -- cgit v1.2.3