Skip to content

Commit

Permalink
Allow critical event log to be exported with mixed 3.2.x and 3.3 form…
Browse files Browse the repository at this point in the history
…ats (LoopKit#532)

* allow critical event log to be exported with mixed 3.2.x and 3.3 formats

* Added printout of value to the log

---------

Co-authored-by: Jonas Björkert <[email protected]>
  • Loading branch information
marionbarker and bjorkert authored Jul 6, 2024
1 parent 2f535b3 commit 873b3b7
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions LoopKit/JSONStreamEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,19 @@ public class JSONStreamEncoder {
}

for value in values {
try stream.write(encoded ? ",\n" : "[\n")
try stream.write(try Self.encoder.encode(value))
encoded = true
do {
let encodedData = try Self.encoder.encode(value)
try stream.write(encoded ? ",\n" : "[\n")
try stream.write(encodedData)
encoded = true
} catch {
// Log the error and insert a placeholder or error message in the JSON
print("Failed to encode value: \(value) with error: \(error.localizedDescription)")
let errorInfo = "{\"error\": \"Failed to encode value: \(value) due to: \(error.localizedDescription)\"}"
try stream.write(encoded ? ",\n" : "[\n")
try stream.write(errorInfo.data(using: .utf8)!)
encoded = true
}
}
}

Expand Down

0 comments on commit 873b3b7

Please sign in to comment.