Skip to content

Commit

Permalink
Revert Data -> String changes for upcoming rule change.
Browse files Browse the repository at this point in the history
This reverts part of 8a58691.
  • Loading branch information
pixlwave committed Jun 4, 2024
1 parent 8a58691 commit bbc772a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ElementX/Sources/Other/Extensions/Dictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension Dictionary {
options: [.fragmentsAllowed, .sortedKeys]) else {
return nil
}
return String(decoding: data, as: UTF8.self)
return String(data: data, encoding: .utf8)
}

/// Returns a dictionary containing the original values keyed by the results of mapping the given closure over its keys.
Expand Down
4 changes: 2 additions & 2 deletions ElementX/Sources/Services/BugReport/BugReportService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ class BugReportService: NSObject, BugReportServiceProtocol {
let (data, response) = try await session.dataWithRetry(for: request, delegate: self)

guard let httpResponse = response as? HTTPURLResponse else {
let errorDescription = String(decoding: data, as: UTF8.self).trimmingCharacters(in: .whitespacesAndNewlines)
let errorDescription = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "Unknown"
MXLog.error("Failed to submit bug report: \(errorDescription)")
MXLog.error("Response: \(response)")
return .failure(.serverError(response, errorDescription))
}

guard httpResponse.statusCode == 200 else {
let errorDescription = String(decoding: data, as: UTF8.self).trimmingCharacters(in: .whitespacesAndNewlines)
let errorDescription = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "Unknown"
MXLog.error("Failed to submit bug report: \(errorDescription) (\(httpResponse.statusCode))")
MXLog.error("Response: \(httpResponse)")
return .failure(.httpError(httpResponse, errorDescription))
Expand Down
2 changes: 1 addition & 1 deletion ElementX/Sources/Services/Timeline/TimelineItemProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ struct TimelineItemDebugInfo: Identifiable, CustomStringConvertible {
return nil
}

return String(decoding: jsonData, as: UTF8.self)
return String(data: jsonData, encoding: .utf8)
}
}

Expand Down
9 changes: 6 additions & 3 deletions ElementX/Sources/UITests/UITestsSignalling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@ enum UITestsSignalling {
let encoder = JSONEncoder()
encoder.outputFormatting = .sortedKeys

guard let data = try? encoder.encode(self) else { return "unknown" }
return String(decoding: data, as: UTF8.self)
guard let data = try? encoder.encode(self),
let string = String(data: data, encoding: .utf8) else {
return "unknown"
}
return string
}

init?(rawValue: String) {
Expand All @@ -172,7 +175,7 @@ enum UITestsSignalling {

/// Processes string data from the file and publishes its signal.
private func processFileData(_ data: Data) {
let rawMessage = String(decoding: data, as: UTF8.self)
guard let rawMessage = String(data: data, encoding: .utf8) else { return }

guard let message = Message(rawValue: rawMessage),
message.mode != mode // Filter out messages sent by this client.
Expand Down

0 comments on commit bbc772a

Please sign in to comment.