From 11d9c32296689155cf322fb0e47b021daa582a9f Mon Sep 17 00:00:00 2001 From: OEBBleo Date: Wed, 5 Nov 2025 10:53:05 +0100 Subject: [PATCH] handle invalid json in state_store --- package/bin/state_store.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/package/bin/state_store.py b/package/bin/state_store.py index 24b0e14..25c5f4b 100644 --- a/package/bin/state_store.py +++ b/package/bin/state_store.py @@ -1,7 +1,9 @@ import os.path as op import os -import json import sys +import json +from json import JSONDecodeError + sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "lib")) from splunklib import client @@ -50,10 +52,14 @@ def get_state(self): fname = op.join(self.checkpoint_dir, self.key) if op.exists(fname): with open(fname) as jsonfile: - state = json.load(jsonfile) - # commented this to disable state cache for local file - # self._states_cache[key] = state - return state + try: + state = json.load(jsonfile) + # commented this to disable state cache for local file + # self._states_cache[key] = state + return state + except JSONDecodeError: + return None + else: return None