JSON parsing lines error handling improved in APIs. See #550
This commit is contained in:
parent
29891df80e
commit
b540e0ba73
4 changed files with 36 additions and 12 deletions
|
|
@ -106,9 +106,15 @@ self.onmessage = async function(event) {
|
||||||
.filter((line) => line !== "" ) // Remove empty lines
|
.filter((line) => line !== "" ) // Remove empty lines
|
||||||
// .map((line) => JSON.parse(line)); // Parse the JSON string
|
// .map((line) => JSON.parse(line)); // Parse the JSON string
|
||||||
.map((line) => {
|
.map((line) => {
|
||||||
|
try {
|
||||||
taLog.log("line: " + JSON.stringify(line));
|
taLog.log("line: " + JSON.stringify(line));
|
||||||
return JSON.parse(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){
|
}catch(e){
|
||||||
taLog.error("Error parsing lines: " + e);
|
taLog.error("Error parsing lines: " + e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,9 +112,15 @@ self.onmessage = async function(event) {
|
||||||
.filter((line) => line !== "" && line !== "[DONE]") // Remove empty lines and "[DONE]"
|
.filter((line) => line !== "" && line !== "[DONE]") // Remove empty lines and "[DONE]"
|
||||||
// .map((line) => JSON.parse(line)); // Parse the JSON string
|
// .map((line) => JSON.parse(line)); // Parse the JSON string
|
||||||
.map((line) => {
|
.map((line) => {
|
||||||
|
try {
|
||||||
taLog.log("line: " + JSON.stringify(line));
|
taLog.log("line: " + JSON.stringify(line));
|
||||||
return JSON.parse(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){
|
}catch(e){
|
||||||
taLog.error("Error parsing lines: " + e);
|
taLog.error("Error parsing lines: " + e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -106,9 +106,15 @@ self.onmessage = async function(event) {
|
||||||
.filter((line) => line !== "" && line !== "[DONE]") // Remove empty lines and "[DONE]"
|
.filter((line) => line !== "" && line !== "[DONE]") // Remove empty lines and "[DONE]"
|
||||||
// .map((line) => JSON.parse(line)); // Parse the JSON string
|
// .map((line) => JSON.parse(line)); // Parse the JSON string
|
||||||
.map((line) => {
|
.map((line) => {
|
||||||
|
try {
|
||||||
taLog.log("line: " + JSON.stringify(line));
|
taLog.log("line: " + JSON.stringify(line));
|
||||||
return JSON.parse(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){
|
}catch(e){
|
||||||
taLog.error("Error parsing lines: " + e);
|
taLog.error("Error parsing lines: " + e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -111,9 +111,15 @@ self.onmessage = async function(event) {
|
||||||
.filter((line) => line !== "" && line !== "[DONE]") // Remove empty lines and "[DONE]"
|
.filter((line) => line !== "" && line !== "[DONE]") // Remove empty lines and "[DONE]"
|
||||||
// .map((line) => JSON.parse(line)); // Parse the JSON string
|
// .map((line) => JSON.parse(line)); // Parse the JSON string
|
||||||
.map((line) => {
|
.map((line) => {
|
||||||
|
try {
|
||||||
taLog.log("line: " + JSON.stringify(line));
|
taLog.log("line: " + JSON.stringify(line));
|
||||||
return JSON.parse(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){
|
}catch(e){
|
||||||
taLog.error("Error parsing lines: " + e);
|
taLog.error("Error parsing lines: " + e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue