Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offering: improved confusing log for PackageType.custom #1884

Merged
merged 1 commit into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Sources/Logging/Strings/OfferingStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ enum OfferingStrings {
case configuration_error_no_products_for_offering
case offering_empty(offeringIdentifier: String)
case product_details_empty_title(productIdentifier: String)
case unknown_package_type(Package)
case custom_package_type(Package)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the cases above have a parameter name in addition to the type. Is that ok? And if so, it might be a good idea to consolidate them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's useful for parameters like Strings because it's not clear what they contain. But a package is always going to be a package 😅


}

Expand Down Expand Up @@ -126,6 +128,11 @@ extension OfferingStrings: CustomStringConvertible {
case let .product_details_empty_title(identifier):
return "Empty Product titles are not supported. Found in product with identifier: \(identifier)"

case let .unknown_package_type(package):
return "Unknown subscription length for package '\(package.offeringIdentifier)'. Ignoring."

case let .custom_package_type(package):
return "Package '\(package.offeringIdentifier)' has a custom duration. Ignoring."
}
}

Expand Down
13 changes: 8 additions & 5 deletions Sources/Purchasing/Offering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ import Foundation
return package(identifier: key)
}

// swiftlint:disable:next cyclomatic_complexity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm might be good to try to refactor this to avoid this issue... But NABD.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought about it but this needs to be in init in order to make the type immutable so I couldn't think of how to extract it out. Ultimately it's just a factor of the number of cases and putting a limit to that is kind of arbitrary.

init(identifier: String, serverDescription: String, availablePackages: [Package]) {
self.identifier = identifier
self.serverDescription = serverDescription
Expand Down Expand Up @@ -138,11 +139,13 @@ import Foundation
case .custom where package.storeProduct.productCategory == .nonSubscription:
// Non-subscription product, ignoring
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still left this extra case because it doesn't even warrant a log.

continue
case .unknown, .custom:
Logger.warn(
"Unknown subscription length for package '\(package.offeringIdentifier)': " +
"\(package.packageType). Ignoring."
)

case .custom:
Logger.debug(Strings.offering.custom_package_type(package))
continue

case .unknown:
Logger.warn(Strings.offering.unknown_package_type(package))
continue
}

Expand Down