[Both] Improves error messages

This commit is contained in:
Riley Testut
2020-03-11 13:35:14 -07:00
parent 4f00018164
commit 5e25593c3d
6 changed files with 141 additions and 43 deletions

View File

@@ -16,6 +16,8 @@ extern NSErrorUserInfoKey const ALTProvisioningProfileBundleIDErrorKey;
typedef NS_ERROR_ENUM(AltServerErrorDomain, ALTServerError)
{
ALTServerErrorUnderlyingError = -1,
ALTServerErrorUnknown = 0,
ALTServerErrorConnectionFailed = 1,
ALTServerErrorLostConnection = 2,
@@ -37,9 +39,7 @@ typedef NS_ERROR_ENUM(AltServerErrorDomain, ALTServerError)
ALTServerErrorInvalidAnisetteData = 13,
ALTServerErrorPluginNotFound = 14,
ALTServerErrorProfileInstallFailed = 15,
ALTServerErrorProfileCopyFailed = 16,
ALTServerErrorProfileRemoveFailed = 17,
ALTServerErrorProfileNotFound = 15
};
NS_ASSUME_NONNULL_BEGIN

View File

@@ -19,19 +19,35 @@ NSErrorUserInfoKey const ALTProvisioningProfileBundleIDErrorKey = @"bundleIdenti
+ (void)load
{
[NSError setUserInfoValueProviderForDomain:AltServerErrorDomain provider:^id _Nullable(NSError * _Nonnull error, NSErrorUserInfoKey _Nonnull userInfoKey) {
if ([userInfoKey isEqualToString:NSLocalizedDescriptionKey])
if ([userInfoKey isEqualToString:NSLocalizedFailureReasonErrorKey])
{
return [error alt_localizedDescription];
return [error alt_localizedFailureReason];
}
if ([userInfoKey isEqualToString:NSLocalizedRecoverySuggestionErrorKey])
{
return [error alt_localizedRecoverySuggestion];
}
return nil;
}];
}
- (nullable NSString *)alt_localizedDescription
- (nullable NSString *)alt_localizedFailureReason
{
switch ((ALTServerError)self.code)
{
case ALTServerErrorUnderlyingError:
{
NSString *underlyingErrorCode = self.userInfo[ALTUnderlyingErrorCodeErrorKey];
if (underlyingErrorCode == nil)
{
return NSLocalizedString(@"An unknown error occured.", @"");
}
return [NSString stringWithFormat:NSLocalizedString(@"Error code: %@", @""), underlyingErrorCode];
}
case ALTServerErrorUnknown:
return NSLocalizedString(@"An unknown error occured.", @"");
@@ -60,7 +76,7 @@ NSErrorUserInfoKey const ALTProvisioningProfileBundleIDErrorKey = @"bundleIdenti
return NSLocalizedString(@"An error occured while installing the app.", @"");
case ALTServerErrorMaximumFreeAppLimitReached:
return NSLocalizedString(@"You have reached the limit of 3 apps per device.", @"");
return NSLocalizedString(@"Cannot activate more than 3 apps and app extensions.", @"");
case ALTServerErrorUnsupportediOSVersion:
return NSLocalizedString(@"Your device must be running iOS 12.2 or later to install AltStore.", @"");
@@ -75,41 +91,43 @@ NSErrorUserInfoKey const ALTProvisioningProfileBundleIDErrorKey = @"bundleIdenti
return NSLocalizedString(@"Invalid anisette data.", @"");
case ALTServerErrorPluginNotFound:
return NSLocalizedString(@"Could not connect to Mail plug-in. Please make sure Mail is running and that you've enabled the plug-in in Mail's preferences, then try again.", @"");
return NSLocalizedString(@"Could not connect to Mail plug-in.", @"");
case ALTServerErrorProfileInstallFailed:
return [self underlyingProfileErrorLocalizedDescriptionWithBaseDescription:NSLocalizedString(@"Could not install profile", "")];
case ALTServerErrorProfileCopyFailed:
return [self underlyingProfileErrorLocalizedDescriptionWithBaseDescription:NSLocalizedString(@"Could not copy provisioning profiles", "")];
case ALTServerErrorProfileRemoveFailed:
return [self underlyingProfileErrorLocalizedDescriptionWithBaseDescription:NSLocalizedString(@"Could not remove profile", "")];
case ALTServerErrorProfileNotFound:
return [self profileErrorLocalizedDescriptionWithBaseDescription:NSLocalizedString(@"Could not find profile", "")];
}
}
- (NSString *)underlyingProfileErrorLocalizedDescriptionWithBaseDescription:(NSString *)baseDescription
- (nullable NSString *)alt_localizedRecoverySuggestion
{
NSMutableString *localizedDescription = [NSMutableString string];
switch ((ALTServerError)self.code)
{
case ALTServerErrorConnectionFailed:
case ALTServerErrorDeviceNotFound:
return NSLocalizedString(@"Make sure you have trusted this phone with your computer and WiFi sync is enabled.", @"");
case ALTServerErrorPluginNotFound:
return NSLocalizedString(@"Make sure Mail is running and the plug-in is enabled in Mail's preferences.", @"");
default:
return nil;
}
}
- (NSString *)profileErrorLocalizedDescriptionWithBaseDescription:(NSString *)baseDescription
{
NSString *localizedDescription = nil;
NSString *bundleID = self.userInfo[ALTProvisioningProfileBundleIDErrorKey];
if (bundleID)
{
[localizedDescription appendFormat:NSLocalizedString(@"%@ “%@”", @""), baseDescription, bundleID];
localizedDescription = [NSString stringWithFormat:@"%@ “%@”", baseDescription, bundleID];
}
else
{
[localizedDescription appendString:baseDescription];
localizedDescription = [NSString stringWithFormat:@"%@.", baseDescription];
}
NSString *underlyingErrorCode = self.userInfo[ALTUnderlyingErrorCodeErrorKey];
if (underlyingErrorCode)
{
[localizedDescription appendFormat:@" (%@)", underlyingErrorCode];
}
[localizedDescription appendString:@"."];
return localizedDescription;
}