Skip to content

Commit

Permalink
RUMM-1870 Report decryption failure
Browse files Browse the repository at this point in the history
  • Loading branch information
maxep committed Apr 4, 2022
1 parent 7f2da6e commit 748ea4c
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions Sources/Datadog/Core/Persistence/Reading/FileReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,32 @@ internal final class FileReader: Reader {
return data
}

var failure: String? = nil
defer {
failure.map { userLogger.error($0) }
}

return data
// split data
.split(separator: dataFormat.separatorByte)
// decode base64 - allow failure
.compactMap { Data(base64Encoded: $0) }
// decrypt data - allow failure
.compactMap { try? encryption.decrypt(data: $0) }
// decode base64 - report failure
.compactMap {
if let data = Data(base64Encoded: $0) {
return data
}

failure = "🔥 Failed to decode base64 data before decryption"
return nil
}
// decrypt data - report failure
.compactMap { (data: Data) in
do {
return try encryption.decrypt(data: data)
} catch {
failure = "🔥 Failed to decrypt data with error: \(error)"
return nil
}
}
// concat data
.reduce(Data()) { $0 + $1 + [dataFormat.separatorByte] }
// drop last separator
Expand Down

0 comments on commit 748ea4c

Please sign in to comment.