Try this to deal with the wonky node-persist library.

This commit is contained in:
Marco van Dijk 2025-01-07 21:42:03 +01:00
parent e779bbc393
commit ca7ff2ef55

View File

@ -162,11 +162,11 @@ async function recoverStorage(initPrometheus) {
console.log("Initialized Prometheus state."); console.log("Initialized Prometheus state.");
} }
function writeToStorage(key, data) { async function writeToStorage(key, data) {
try { try {
const serialized = JSON.stringify(data); const serialized = JSON.stringify(data);
if (!serialized) throw new Error("Invalid JSON data"); if (!serialized || !serialized.length) throw new Error("Invalid JSON data");
storage.setItem(key, JSON.parse(serialized)); await storage.setItem(key, JSON.parse(serialized));
console.log(`Stored data for key: ${key}`); console.log(`Stored data for key: ${key}`);
} catch (err) { } catch (err) {
console.error(`Error writing to storage for key: ${key}`, err.message); console.error(`Error writing to storage for key: ${key}`, err.message);