JSON parsing lines error handling improved in APIs. See #550

This commit is contained in:
mic 2025-12-14 22:19:04 +01:00
parent 29891df80e
commit b540e0ba73
4 changed files with 36 additions and 12 deletions

View file

@ -106,9 +106,15 @@ self.onmessage = async function(event) {
.filter((line) => line !== "" ) // Remove empty lines
// .map((line) => JSON.parse(line)); // Parse the JSON string
.map((line) => {
taLog.log("line: " + JSON.stringify(line));
return JSON.parse(line);
});
try {
taLog.log("line: " + JSON.stringify(line));
return JSON.parse(line);
} catch (e) {
taLog.warn("JSON parse warning, skipped line: " + line + " - " + e.message);
return null;
}
})
.filter((parsed) => parsed !== null);
}catch(e){
taLog.error("Error parsing lines: " + e);
}

View file

@ -112,9 +112,15 @@ self.onmessage = async function(event) {
.filter((line) => line !== "" && line !== "[DONE]") // Remove empty lines and "[DONE]"
// .map((line) => JSON.parse(line)); // Parse the JSON string
.map((line) => {
taLog.log("line: " + JSON.stringify(line));
return JSON.parse(line);
});
try {
taLog.log("line: " + JSON.stringify(line));
return JSON.parse(line);
} catch (e) {
taLog.warn("JSON parse warning, skipped line: " + line + " - " + e.message);
return null;
}
})
.filter((parsed) => parsed !== null);
}catch(e){
taLog.error("Error parsing lines: " + e);
}

View file

@ -106,9 +106,15 @@ self.onmessage = async function(event) {
.filter((line) => line !== "" && line !== "[DONE]") // Remove empty lines and "[DONE]"
// .map((line) => JSON.parse(line)); // Parse the JSON string
.map((line) => {
taLog.log("line: " + JSON.stringify(line));
return JSON.parse(line);
});
try {
taLog.log("line: " + JSON.stringify(line));
return JSON.parse(line);
} catch (e) {
taLog.warn("JSON parse warning, skipped line: " + line + " - " + e.message);
return null;
}
})
.filter((parsed) => parsed !== null);
}catch(e){
taLog.error("Error parsing lines: " + e);
}

View file

@ -111,9 +111,15 @@ self.onmessage = async function(event) {
.filter((line) => line !== "" && line !== "[DONE]") // Remove empty lines and "[DONE]"
// .map((line) => JSON.parse(line)); // Parse the JSON string
.map((line) => {
taLog.log("line: " + JSON.stringify(line));
return JSON.parse(line);
});
try {
taLog.log("line: " + JSON.stringify(line));
return JSON.parse(line);
} catch (e) {
taLog.warn("JSON parse warning, skipped line: " + line + " - " + e.message);
return null;
}
})
.filter((parsed) => parsed !== null);
}catch(e){
taLog.error("Error parsing lines: " + e);
}