Skip to content

Commit

Permalink
Do not crash when tw_get_packages returned -1
Browse files Browse the repository at this point in the history
  • Loading branch information
danpashin committed Jun 14, 2024
1 parent 32dc60f commit 740a947
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions twackup-gui/Twackup/Sources/FFI Models/Dpkg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@

import Sentry

enum DpkgError: Error, LocalizedError {
case `internal`

var errorDescription: String? {
switch self {
case .internal: "Internal error. Needs more details"
}
}
}

actor Dpkg {
enum MessageLevel: UInt8 {
case debug
Expand Down Expand Up @@ -42,6 +52,9 @@ actor Dpkg {
func parsePackages(onlyLeaves: Bool) throws -> [FFIPackage] {
var packagesPtr: UnsafeMutablePointer<TwPackage>?
let count = tw_get_packages(innerDpkg, onlyLeaves, TW_PACKAGES_SORT_NAME.clampedToU8, &packagesPtr)
if count == -1 {
throw DpkgError.internal
}

let buffer = UnsafeBufferPointer(start: packagesPtr, count: Int(count))
defer { tw_free_packages(packagesPtr, count) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DpkgDataProvier: PackageDataProvider, @unchecked Sendable {
do {
allPackages = try await dpkg.parsePackages(onlyLeaves: onlyLeaves)
} catch {
await FFILogger.shared.log("\(error)", level: .error)
await FFILogger.shared.log("Error \(error): \(error.localizedDescription)", level: .error)
SentrySDK.capture(error: error)
}

Expand Down

0 comments on commit 740a947

Please sign in to comment.