diff --git a/CODING_GUIDELINES.md b/CODING_GUIDELINES.md index b533aad4..d89156ee 100644 --- a/CODING_GUIDELINES.md +++ b/CODING_GUIDELINES.md @@ -73,6 +73,8 @@ These should usually be prioritized in that order, but adjust the trade-off as n - **Write API docs** using [DocC syntax][] (a Markdown dialect), unless an API is trivial (or not app-team-facing). Even for internal methods, though, if you do write a comment, make it a doc comment (like for Rust code), because it shows up in IDEs. +- To make sure that error messages get into logs, we use the `failOnError` helper instead of `try!` for forcing an unwrap on the result of an operation that can throw an error. + [DocC syntax]: https://www.swift.org/documentation/docc/writing-symbol-documentation-in-your-source-files diff --git a/swift/Sources/LibSignalClient/MessageBackup.swift b/swift/Sources/LibSignalClient/MessageBackup.swift index 10d4e720..699e2209 100644 --- a/swift/Sources/LibSignalClient/MessageBackup.swift +++ b/swift/Sources/LibSignalClient/MessageBackup.swift @@ -75,9 +75,11 @@ public struct MessageBackupUnknownFields { private class ValidationOutcome: NativeHandleOwner { public var unknownFields: MessageBackupUnknownFields { - let fields = try! self.withNativeHandle { result in - try invokeFnReturningStringArray { - signal_message_backup_validation_outcome_get_unknown_fields($0, result) + let fields = failOnError { + try self.withNativeHandle { result in + try invokeFnReturningStringArray { + signal_message_backup_validation_outcome_get_unknown_fields($0, result) + } } } return MessageBackupUnknownFields(fields: fields) diff --git a/swift/Sources/LibSignalClient/SealedSenderCertificates.swift b/swift/Sources/LibSignalClient/SealedSenderCertificates.swift index 073e29d2..c30191f1 100644 --- a/swift/Sources/LibSignalClient/SealedSenderCertificates.swift +++ b/swift/Sources/LibSignalClient/SealedSenderCertificates.swift @@ -198,7 +198,9 @@ public class SenderCertificate: NativeHandleOwner { } public var sender: SealedSenderAddress { - return try! SealedSenderAddress(e164: self.senderE164, uuidString: self.senderUuid, deviceId: self.deviceId) + return failOnError { + try SealedSenderAddress(e164: self.senderE164, uuidString: self.senderUuid, deviceId: self.deviceId) + } } public var serverCertificate: ServerCertificate {