mirror of
https://github.com/GayPizzaSpecifications/darwin-apk.git
synced 2025-08-04 05:51:31 +00:00
Improve indexing error messages
This commit is contained in:
@ -3,6 +3,8 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct ApkIndex: Sendable {
|
||||
public let packages: [ApkIndexPackage]
|
||||
}
|
||||
@ -32,9 +34,13 @@ public extension ApkIndex {
|
||||
}
|
||||
|
||||
extension ApkIndex {
|
||||
init(raw: ApkRawIndex) throws {
|
||||
self.packages = try raw.packages.map {
|
||||
try ApkIndexPackage(raw: $0)
|
||||
init(raw: ApkRawIndex) throws(ApkIndexError) {
|
||||
self.packages = try raw.packages.map { records throws(ApkIndexError) in
|
||||
do {
|
||||
return try ApkIndexPackage(raw: records)
|
||||
} catch {
|
||||
throw .parseError(records.lookup("P") ?? "UNKNOWN", error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -44,3 +50,16 @@ extension ApkIndex: CustomStringConvertible {
|
||||
self.packages.map(String.init).joined(separator: "\n")
|
||||
}
|
||||
}
|
||||
|
||||
public enum ApkIndexError: Error {
|
||||
case parseError(String, any Error)
|
||||
}
|
||||
|
||||
extension ApkIndexError: LocalizedError {
|
||||
public var errorDescription: String? {
|
||||
switch self {
|
||||
case .parseError(let packageName, let cause):
|
||||
return "Failed to parse index for \"\(packageName)\": \(cause.localizedDescription)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user