From b5d49a63cfb5d24e581260b4af988c263b613d04 Mon Sep 17 00:00:00 2001 From: Kabir Oberai Date: Fri, 23 May 2025 19:05:02 +0530 Subject: [PATCH] Improve OpenAPI error handling (#78) - Make some enums non-exhaustive (closes #77) - Also a tentative fix for #62 and #64 - Improve logging on deserialization failure We now use raw JS to patch the OpenAPI spec instead of openapi-overlay. It's a lot more flexible this way. --- Makefile | 4 +- Package.swift | 2 +- Sources/DeveloperAPI/Generated/Types.swift | 309 ++++++++++++++---- Sources/DeveloperAPI/openapi-overlay.yaml | 42 --- Sources/DeveloperAPI/patch.js | 59 ++++ .../DeveloperServicesAddAppOperation.swift | 6 +- .../DeveloperServicesCapability.swift | 4 +- ...perServicesFetchCertificateOperation.swift | 2 +- .../DeveloperServices+OpenAPI.swift | 24 ++ ...eveloperServicesFetchDeviceOperation.swift | 2 +- Sources/XToolSupport/DevCommand.swift | 9 +- Sources/XToolSupport/InstallCommand.swift | 6 +- 12 files changed, 352 insertions(+), 117 deletions(-) delete mode 100644 Sources/DeveloperAPI/openapi-overlay.yaml create mode 100644 Sources/DeveloperAPI/patch.js diff --git a/Makefile b/Makefile index 826b7ed1..a7bd312e 100644 --- a/Makefile +++ b/Makefile @@ -144,8 +144,8 @@ api: openapi/openapi.json update-api: @+$(MAKE) -B api -openapi/openapi.json: openapi/base.json Sources/DeveloperAPI/openapi-overlay.yaml - npx --yes bump-cli overlay openapi/base.json Sources/DeveloperAPI/openapi-overlay.yaml > openapi/openapi.json +openapi/openapi.json: openapi/base.json Sources/DeveloperAPI/patch.js + node Sources/DeveloperAPI/patch.js < openapi/base.json > openapi/openapi.json openapi/base.json: @mkdir -p openapi diff --git a/Package.swift b/Package.swift index 3d85b24f..2cadb585 100644 --- a/Package.swift +++ b/Package.swift @@ -88,7 +88,7 @@ let package = Package( dependencies: [ .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"), ], - exclude: ["openapi-generator-config.yaml", "openapi-overlay.yaml"] + exclude: ["openapi-generator-config.yaml", "patch.js"] ), .target( name: "XKit", diff --git a/Sources/DeveloperAPI/Generated/Types.swift b/Sources/DeveloperAPI/Generated/Types.swift index ace7e465..f23522a0 100644 --- a/Sources/DeveloperAPI/Generated/Types.swift +++ b/Sources/DeveloperAPI/Generated/Types.swift @@ -3464,14 +3464,60 @@ public enum Components { /// - Remark: Generated from `#/components/schemas/Device/attributes/udid`. public var udid: Swift.String? /// - Remark: Generated from `#/components/schemas/Device/attributes/deviceClass`. - @frozen public enum DeviceClassPayload: String, Codable, Hashable, Sendable, CaseIterable { - case appleWatch = "APPLE_WATCH" - case ipad = "IPAD" - case iphone = "IPHONE" - case ipod = "IPOD" - case appleTv = "APPLE_TV" - case mac = "MAC" - case appleVisionPro = "APPLE_VISION_PRO" + public struct DeviceClassPayload: Codable, Hashable, Sendable { + /// - Remark: Generated from `#/components/schemas/Device/attributes/deviceClass/value1`. + @frozen public enum Value1Payload: String, Codable, Hashable, Sendable, CaseIterable { + case appleWatch = "APPLE_WATCH" + case ipad = "IPAD" + case iphone = "IPHONE" + case ipod = "IPOD" + case appleTv = "APPLE_TV" + case mac = "MAC" + } + /// - Remark: Generated from `#/components/schemas/Device/attributes/deviceClass/value1`. + public var value1: Components.Schemas.Device.AttributesPayload.DeviceClassPayload.Value1Payload? + /// - Remark: Generated from `#/components/schemas/Device/attributes/deviceClass/value2`. + public var value2: Swift.String? + /// Creates a new `DeviceClassPayload`. + /// + /// - Parameters: + /// - value1: + /// - value2: + public init( + value1: Components.Schemas.Device.AttributesPayload.DeviceClassPayload.Value1Payload? = nil, + value2: Swift.String? = nil + ) { + self.value1 = value1 + self.value2 = value2 + } + public init(from decoder: any Decoder) throws { + var errors: [any Error] = [] + do { + self.value1 = try decoder.decodeFromSingleValueContainer() + } catch { + errors.append(error) + } + do { + self.value2 = try decoder.decodeFromSingleValueContainer() + } catch { + errors.append(error) + } + try Swift.DecodingError.verifyAtLeastOneSchemaIsNotNil( + [ + self.value1, + self.value2 + ], + type: Self.self, + codingPath: decoder.codingPath, + errors: errors + ) + } + public func encode(to encoder: any Encoder) throws { + try encoder.encodeFirstNonNilValueToSingleValueContainer([ + self.value1, + self.value2 + ]) + } } /// - Remark: Generated from `#/components/schemas/Device/attributes/deviceClass`. public var deviceClass: Components.Schemas.Device.AttributesPayload.DeviceClassPayload? @@ -5015,12 +5061,57 @@ public enum Components { } } /// - Remark: Generated from `#/components/schemas/BundleIdPlatform`. - @frozen public enum BundleIdPlatform: String, Codable, Hashable, Sendable, CaseIterable { - case ios = "IOS" - case macOs = "MAC_OS" - case universal = "UNIVERSAL" - case services = "SERVICES" - case macos = "MACOS" + public struct BundleIdPlatform: Codable, Hashable, Sendable { + /// - Remark: Generated from `#/components/schemas/BundleIdPlatform/value1`. + @frozen public enum Value1Payload: String, Codable, Hashable, Sendable, CaseIterable { + case ios = "IOS" + case macOs = "MAC_OS" + case universal = "UNIVERSAL" + } + /// - Remark: Generated from `#/components/schemas/BundleIdPlatform/value1`. + public var value1: Components.Schemas.BundleIdPlatform.Value1Payload? + /// - Remark: Generated from `#/components/schemas/BundleIdPlatform/value2`. + public var value2: Swift.String? + /// Creates a new `BundleIdPlatform`. + /// + /// - Parameters: + /// - value1: + /// - value2: + public init( + value1: Components.Schemas.BundleIdPlatform.Value1Payload? = nil, + value2: Swift.String? = nil + ) { + self.value1 = value1 + self.value2 = value2 + } + public init(from decoder: any Decoder) throws { + var errors: [any Error] = [] + do { + self.value1 = try decoder.decodeFromSingleValueContainer() + } catch { + errors.append(error) + } + do { + self.value2 = try decoder.decodeFromSingleValueContainer() + } catch { + errors.append(error) + } + try Swift.DecodingError.verifyAtLeastOneSchemaIsNotNil( + [ + self.value1, + self.value2 + ], + type: Self.self, + codingPath: decoder.codingPath, + errors: errors + ) + } + public func encode(to encoder: any Encoder) throws { + try encoder.encodeFirstNonNilValueToSingleValueContainer([ + self.value1, + self.value2 + ]) + } } /// - Remark: Generated from `#/components/schemas/CapabilityOption`. public struct CapabilityOption: Codable, Hashable, Sendable { @@ -5150,56 +5241,150 @@ public enum Components { } } /// - Remark: Generated from `#/components/schemas/CapabilityType`. - @frozen public enum CapabilityType: String, Codable, Hashable, Sendable, CaseIterable { - case icloud = "ICLOUD" - case inAppPurchase = "IN_APP_PURCHASE" - case gameCenter = "GAME_CENTER" - case pushNotifications = "PUSH_NOTIFICATIONS" - case wallet = "WALLET" - case interAppAudio = "INTER_APP_AUDIO" - case maps = "MAPS" - case associatedDomains = "ASSOCIATED_DOMAINS" - case personalVpn = "PERSONAL_VPN" - case appGroups = "APP_GROUPS" - case healthkit = "HEALTHKIT" - case homekit = "HOMEKIT" - case wirelessAccessoryConfiguration = "WIRELESS_ACCESSORY_CONFIGURATION" - case applePay = "APPLE_PAY" - case dataProtection = "DATA_PROTECTION" - case sirikit = "SIRIKIT" - case networkExtensions = "NETWORK_EXTENSIONS" - case multipath = "MULTIPATH" - case hotSpot = "HOT_SPOT" - case nfcTagReading = "NFC_TAG_READING" - case classkit = "CLASSKIT" - case autofillCredentialProvider = "AUTOFILL_CREDENTIAL_PROVIDER" - case accessWifiInformation = "ACCESS_WIFI_INFORMATION" - case networkCustomProtocol = "NETWORK_CUSTOM_PROTOCOL" - case coremediaHlsLowLatency = "COREMEDIA_HLS_LOW_LATENCY" - case systemExtensionInstall = "SYSTEM_EXTENSION_INSTALL" - case userManagement = "USER_MANAGEMENT" - case appleIdAuth = "APPLE_ID_AUTH" + public struct CapabilityType: Codable, Hashable, Sendable { + /// - Remark: Generated from `#/components/schemas/CapabilityType/value1`. + @frozen public enum Value1Payload: String, Codable, Hashable, Sendable, CaseIterable { + case icloud = "ICLOUD" + case inAppPurchase = "IN_APP_PURCHASE" + case gameCenter = "GAME_CENTER" + case pushNotifications = "PUSH_NOTIFICATIONS" + case wallet = "WALLET" + case interAppAudio = "INTER_APP_AUDIO" + case maps = "MAPS" + case associatedDomains = "ASSOCIATED_DOMAINS" + case personalVpn = "PERSONAL_VPN" + case appGroups = "APP_GROUPS" + case healthkit = "HEALTHKIT" + case homekit = "HOMEKIT" + case wirelessAccessoryConfiguration = "WIRELESS_ACCESSORY_CONFIGURATION" + case applePay = "APPLE_PAY" + case dataProtection = "DATA_PROTECTION" + case sirikit = "SIRIKIT" + case networkExtensions = "NETWORK_EXTENSIONS" + case multipath = "MULTIPATH" + case hotSpot = "HOT_SPOT" + case nfcTagReading = "NFC_TAG_READING" + case classkit = "CLASSKIT" + case autofillCredentialProvider = "AUTOFILL_CREDENTIAL_PROVIDER" + case accessWifiInformation = "ACCESS_WIFI_INFORMATION" + case networkCustomProtocol = "NETWORK_CUSTOM_PROTOCOL" + case coremediaHlsLowLatency = "COREMEDIA_HLS_LOW_LATENCY" + case systemExtensionInstall = "SYSTEM_EXTENSION_INSTALL" + case userManagement = "USER_MANAGEMENT" + case appleIdAuth = "APPLE_ID_AUTH" + } + /// - Remark: Generated from `#/components/schemas/CapabilityType/value1`. + public var value1: Components.Schemas.CapabilityType.Value1Payload? + /// - Remark: Generated from `#/components/schemas/CapabilityType/value2`. + public var value2: Swift.String? + /// Creates a new `CapabilityType`. + /// + /// - Parameters: + /// - value1: + /// - value2: + public init( + value1: Components.Schemas.CapabilityType.Value1Payload? = nil, + value2: Swift.String? = nil + ) { + self.value1 = value1 + self.value2 = value2 + } + public init(from decoder: any Decoder) throws { + var errors: [any Error] = [] + do { + self.value1 = try decoder.decodeFromSingleValueContainer() + } catch { + errors.append(error) + } + do { + self.value2 = try decoder.decodeFromSingleValueContainer() + } catch { + errors.append(error) + } + try Swift.DecodingError.verifyAtLeastOneSchemaIsNotNil( + [ + self.value1, + self.value2 + ], + type: Self.self, + codingPath: decoder.codingPath, + errors: errors + ) + } + public func encode(to encoder: any Encoder) throws { + try encoder.encodeFirstNonNilValueToSingleValueContainer([ + self.value1, + self.value2 + ]) + } } /// - Remark: Generated from `#/components/schemas/CertificateType`. - @frozen public enum CertificateType: String, Codable, Hashable, Sendable, CaseIterable { - case applePay = "APPLE_PAY" - case applePayMerchantIdentity = "APPLE_PAY_MERCHANT_IDENTITY" - case applePayPspIdentity = "APPLE_PAY_PSP_IDENTITY" - case applePayRsa = "APPLE_PAY_RSA" - case developerIdKext = "DEVELOPER_ID_KEXT" - case developerIdKextG2 = "DEVELOPER_ID_KEXT_G2" - case developerIdApplication = "DEVELOPER_ID_APPLICATION" - case developerIdApplicationG2 = "DEVELOPER_ID_APPLICATION_G2" - case development = "DEVELOPMENT" - case distribution = "DISTRIBUTION" - case identityAccess = "IDENTITY_ACCESS" - case iosDevelopment = "IOS_DEVELOPMENT" - case iosDistribution = "IOS_DISTRIBUTION" - case macAppDistribution = "MAC_APP_DISTRIBUTION" - case macInstallerDistribution = "MAC_INSTALLER_DISTRIBUTION" - case macAppDevelopment = "MAC_APP_DEVELOPMENT" - case passTypeId = "PASS_TYPE_ID" - case passTypeIdWithNfc = "PASS_TYPE_ID_WITH_NFC" + public struct CertificateType: Codable, Hashable, Sendable { + /// - Remark: Generated from `#/components/schemas/CertificateType/value1`. + @frozen public enum Value1Payload: String, Codable, Hashable, Sendable, CaseIterable { + case applePay = "APPLE_PAY" + case applePayMerchantIdentity = "APPLE_PAY_MERCHANT_IDENTITY" + case applePayPspIdentity = "APPLE_PAY_PSP_IDENTITY" + case applePayRsa = "APPLE_PAY_RSA" + case developerIdKext = "DEVELOPER_ID_KEXT" + case developerIdKextG2 = "DEVELOPER_ID_KEXT_G2" + case developerIdApplication = "DEVELOPER_ID_APPLICATION" + case developerIdApplicationG2 = "DEVELOPER_ID_APPLICATION_G2" + case development = "DEVELOPMENT" + case distribution = "DISTRIBUTION" + case identityAccess = "IDENTITY_ACCESS" + case iosDevelopment = "IOS_DEVELOPMENT" + case iosDistribution = "IOS_DISTRIBUTION" + case macAppDistribution = "MAC_APP_DISTRIBUTION" + case macInstallerDistribution = "MAC_INSTALLER_DISTRIBUTION" + case macAppDevelopment = "MAC_APP_DEVELOPMENT" + case passTypeId = "PASS_TYPE_ID" + case passTypeIdWithNfc = "PASS_TYPE_ID_WITH_NFC" + } + /// - Remark: Generated from `#/components/schemas/CertificateType/value1`. + public var value1: Components.Schemas.CertificateType.Value1Payload? + /// - Remark: Generated from `#/components/schemas/CertificateType/value2`. + public var value2: Swift.String? + /// Creates a new `CertificateType`. + /// + /// - Parameters: + /// - value1: + /// - value2: + public init( + value1: Components.Schemas.CertificateType.Value1Payload? = nil, + value2: Swift.String? = nil + ) { + self.value1 = value1 + self.value2 = value2 + } + public init(from decoder: any Decoder) throws { + var errors: [any Error] = [] + do { + self.value1 = try decoder.decodeFromSingleValueContainer() + } catch { + errors.append(error) + } + do { + self.value2 = try decoder.decodeFromSingleValueContainer() + } catch { + errors.append(error) + } + try Swift.DecodingError.verifyAtLeastOneSchemaIsNotNil( + [ + self.value1, + self.value2 + ], + type: Self.self, + codingPath: decoder.codingPath, + errors: errors + ) + } + public func encode(to encoder: any Encoder) throws { + try encoder.encodeFirstNonNilValueToSingleValueContainer([ + self.value1, + self.value2 + ]) + } } /// - Remark: Generated from `#/components/schemas/SubscriptionStatusUrlVersion`. @frozen public enum SubscriptionStatusUrlVersion: String, Codable, Hashable, Sendable, CaseIterable { diff --git a/Sources/DeveloperAPI/openapi-overlay.yaml b/Sources/DeveloperAPI/openapi-overlay.yaml deleted file mode 100644 index 17bd2405..00000000 --- a/Sources/DeveloperAPI/openapi-overlay.yaml +++ /dev/null @@ -1,42 +0,0 @@ -overlay: 1.0.0 -info: - title: Overlay for App Store Connect API - version: 1.0.0 -actions: - # this field is required when using the private Xcode API - - target: '$.components.schemas.BundleIdCapabilityCreateRequest.properties.data.properties.relationships' - update: - properties: - capability: - type: object - properties: - data: - type: object - properties: - type: - type: string - enum: [capabilities] - id: - "$ref": "#/components/schemas/CapabilityType" - required: [id, type] - required: [data] - required: [capability] - # we don't use this but it triggers a deprecation warning. see: - # https://github.com/apple/swift-openapi-generator/issues/715 - - target: '$.components.schemas.App.properties.relationships.properties.inAppPurchases' - update: - deprecated: false - # openapi-generator expects response enums to be exhaustive. Apple's ASC OpenAPI spec - # misses some cases that they do, actually, return. - - target: '$.components.schemas.Device.properties.attributes.properties.deviceClass' - update: - enum: - - APPLE_VISION_PRO - - target: '$.components.schemas.BundleIdPlatform' - update: - enum: - - SERVICES - # the spec already declares MAC_OS but ASC sometimes seems to - # spell this as MACOS instead. see: - # https://github.com/xtool-org/xtool/issues/64 - - MACOS diff --git a/Sources/DeveloperAPI/patch.js b/Sources/DeveloperAPI/patch.js new file mode 100644 index 00000000..064af46e --- /dev/null +++ b/Sources/DeveloperAPI/patch.js @@ -0,0 +1,59 @@ +#!/usr/bin/env node + +import fs from 'fs'; + +function makeOpen(enumSchema) { + const copy = structuredClone(enumSchema); + Object.keys(enumSchema).forEach(k => delete enumSchema[k]); + Object.assign(enumSchema, { + anyOf: [ + copy, + { type: 'string' }, + ] + }) +} + +function format(schema) { + const schemas = schema.components.schemas; + + // this field is required when using the private Xcode API + const capabilityCreateRelationships = schemas.BundleIdCapabilityCreateRequest.properties.data.properties.relationships; + capabilityCreateRelationships.properties.capability = { + type: 'object', + properties: { + data: { + type: 'object', + properties: { + type: { + type: 'string', + enum: ['capabilities'], + }, + id: { $ref: '#/components/schemas/CapabilityType' }, + }, + required: ['id', 'type'], + }, + }, + required: ['data'], + } + capabilityCreateRelationships.required.push('capability'); + + // we don't use this but it triggers a deprecation warning. see: + // https://github.com/apple/swift-openapi-generator/issues/715 + schemas.App.properties.relationships.properties.inAppPurchases.deprecated = false; + + // openapi-generator expects response enums to be exhaustive. Apple's ASC OpenAPI spec + // misses some cases that they do, actually, return. + // https://swiftpackageindex.com/apple/swift-openapi-generator/1.7.2/documentation/swift-openapi-generator/useful-openapi-patterns#Open-enums-and-oneOfs + makeOpen(schemas.BundleIdPlatform); + makeOpen(schemas.CapabilityType); + makeOpen(schemas.CertificateType); + makeOpen(schemas.Device.properties.attributes.properties.deviceClass); + + return schema; +} + +const text = fs.readFileSync(process.stdin.fd, 'utf8'); +const json = JSON.parse(text); +const formatted = format(json); +const formattedText = JSON.stringify(formatted); +console.log(formattedText); diff --git a/Sources/XKit/DeveloperServices/App IDs/DeveloperServicesAddAppOperation.swift b/Sources/XKit/DeveloperServices/App IDs/DeveloperServicesAddAppOperation.swift index 90684f8a..0be5c699 100644 --- a/Sources/XKit/DeveloperServices/App IDs/DeveloperServicesAddAppOperation.swift +++ b/Sources/XKit/DeveloperServices/App IDs/DeveloperServicesAddAppOperation.swift @@ -57,7 +57,7 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation { _type: .bundleIds, attributes: .init( name: name, - platform: .ios, + platform: .init(.ios), identifier: newBundleID ) ) @@ -105,8 +105,8 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation { } } else { // DeveloperServices doesn't allow deleting these capabilities - let requiredCapabilities: Set = [.inAppPurchase] - if let capType = cap.attributes?.capabilityType, !requiredCapabilities.contains(capType) { + let requiredCapabilities: Set = [.inAppPurchase] + if let capType = cap.attributes?.capabilityType?.value1, !requiredCapabilities.contains(capType) { _ = try await context.developerAPIClient .bundleIdCapabilitiesDeleteInstance(path: .init(id: cap.id)) .noContent diff --git a/Sources/XKit/DeveloperServices/App IDs/Entitlements/DeveloperServicesCapability.swift b/Sources/XKit/DeveloperServices/App IDs/Entitlements/DeveloperServicesCapability.swift index 6742ea1b..0cc57f3b 100644 --- a/Sources/XKit/DeveloperServices/App IDs/Entitlements/DeveloperServicesCapability.swift +++ b/Sources/XKit/DeveloperServices/App IDs/Entitlements/DeveloperServicesCapability.swift @@ -15,11 +15,11 @@ public struct DeveloperServicesCapability: Sendable, Hashable { public var settings: [Components.Schemas.CapabilitySetting]? public init( - _ capabilityType: Components.Schemas.CapabilityType, + _ capabilityType: Components.Schemas.CapabilityType.Value1Payload, isFree: Bool, settings: [Components.Schemas.CapabilitySetting]? = nil ) { - self.capabilityType = capabilityType + self.capabilityType = .init(capabilityType) self.isFree = isFree self.settings = settings } diff --git a/Sources/XKit/DeveloperServices/Certificates/DeveloperServicesFetchCertificateOperation.swift b/Sources/XKit/DeveloperServices/Certificates/DeveloperServicesFetchCertificateOperation.swift index 26ae405a..980cb9c9 100644 --- a/Sources/XKit/DeveloperServices/Certificates/DeveloperServicesFetchCertificateOperation.swift +++ b/Sources/XKit/DeveloperServices/Certificates/DeveloperServicesFetchCertificateOperation.swift @@ -54,7 +54,7 @@ public struct DeveloperServicesFetchCertificateOperation: DeveloperServicesOpera _type: .certificates, attributes: .init( csrContent: csr.pemString, - certificateType: .development + certificateType: .init(.development) ) ))) ) diff --git a/Sources/XKit/DeveloperServices/DeveloperServices+OpenAPI.swift b/Sources/XKit/DeveloperServices/DeveloperServices+OpenAPI.swift index 3ba555e2..69da496d 100644 --- a/Sources/XKit/DeveloperServices/DeveloperServices+OpenAPI.swift +++ b/Sources/XKit/DeveloperServices/DeveloperServices+OpenAPI.swift @@ -256,3 +256,27 @@ struct LoggingMiddleware: ClientMiddleware { return (response, body) } } + +// syntactic sugar to make it nicer to work with `anyOf:` types +public protocol OpenAPIExtensibleEnum { + associatedtype Value1Payload: RawRepresentable, Codable, Hashable, Sendable, CaseIterable + var value1: Value1Payload? { get set } + var value2: String? { get set } + + init(value1: Value1Payload?, value2: String?) +} + +extension OpenAPIExtensibleEnum { + public var rawValue: String { + value2! + } + + public init(_ value: Value1Payload) { + self.init(value1: value, value2: nil) + } +} + +extension Components.Schemas.BundleIdPlatform: OpenAPIExtensibleEnum {} +extension Components.Schemas.CapabilityType: OpenAPIExtensibleEnum {} +extension Components.Schemas.CertificateType: OpenAPIExtensibleEnum {} +extension Components.Schemas.Device.AttributesPayload.DeviceClassPayload: OpenAPIExtensibleEnum {} diff --git a/Sources/XKit/DeveloperServices/Devices/DeveloperServicesFetchDeviceOperation.swift b/Sources/XKit/DeveloperServices/Devices/DeveloperServicesFetchDeviceOperation.swift index b5cbc8d4..9f5eaf7d 100644 --- a/Sources/XKit/DeveloperServices/Devices/DeveloperServicesFetchDeviceOperation.swift +++ b/Sources/XKit/DeveloperServices/Devices/DeveloperServicesFetchDeviceOperation.swift @@ -27,7 +27,7 @@ public struct DeveloperServicesFetchDeviceOperation: DeveloperServicesOperation _type: .devices, attributes: .init( name: self.context.deviceName, - platform: .ios, + platform: .init(.ios), udid: self.context.udid ) ))) diff --git a/Sources/XToolSupport/DevCommand.swift b/Sources/XToolSupport/DevCommand.swift index a53bf3eb..0f17abcc 100644 --- a/Sources/XToolSupport/DevCommand.swift +++ b/Sources/XToolSupport/DevCommand.swift @@ -198,7 +198,14 @@ struct DevRunCommand: AsyncParsableCommand { defer { print() } - try await installer.install(app: output) + do { + try await installer.install(app: output) + } catch let error as CancellationError { + throw error + } catch { + print("\nError: \(error)") + throw ExitCode.failure + } } } diff --git a/Sources/XToolSupport/InstallCommand.swift b/Sources/XToolSupport/InstallCommand.swift index b0f4c9bb..e805b588 100644 --- a/Sources/XToolSupport/InstallCommand.swift +++ b/Sources/XToolSupport/InstallCommand.swift @@ -34,9 +34,11 @@ struct InstallCommand: AsyncParsableCommand { do { try await installer.install(app: URL(fileURLWithPath: path)) print("\nSuccessfully installed!") + } catch let error as CancellationError { + throw error } catch { - print("\nFailed :(") - print("Error: \(error)") + print("\nError: \(error)") + throw ExitCode.failure } } }