Skip to content
This repository has been archived by the owner on Sep 4, 2018. It is now read-only.

Commit

Permalink
Truncate error only when presenting it
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed Jun 7, 2016
1 parent 2e55fdc commit 2864836
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 12 additions & 0 deletions Alcatraz/Controllers/ATZPluginWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentN
return YES;
}

- (NSError *)willPresentError:(NSError *)error
{
const NSUInteger maxLength = 500;
NSString *recoverySuggestion = error.userInfo[NSLocalizedRecoverySuggestionErrorKey];
if (recoverySuggestion.length > maxLength) {
NSMutableDictionary *userInfo = [error.userInfo mutableCopy];
userInfo[NSLocalizedRecoverySuggestionErrorKey] = [[recoverySuggestion substringToIndex:MIN(maxLength, recoverySuggestion.length)] stringByAppendingString:@""];
return [NSError errorWithDomain:error.domain code:error.code userInfo:userInfo];
}
return error;
}

#pragma mark - Bindings

- (IBAction)installPressed:(ATZFillableButton *)button {
Expand Down
4 changes: 1 addition & 3 deletions Alcatraz/Helpers/ATZShell.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ - (void)setUpTerminationHandlerForTask:(NSTask *)task completion:(void(^)(NSStri
if (task.terminationStatus == 0) {
completion(output, nil);
} else {
const NSUInteger maxLength = 500;
NSString *truncatedOutput = [[output substringToIndex:MIN(maxLength, output.length)] stringByAppendingString:output.length > maxLength ? @"" : @""];
NSString *description = [NSString stringWithFormat:@"Task exited with status %d\n\n%@ %@", task.terminationStatus, task.launchPath, [task.arguments componentsJoinedByString:@" "]];
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: description, NSLocalizedRecoverySuggestionErrorKey: truncatedOutput };
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: description, NSLocalizedRecoverySuggestionErrorKey: output };
completion(output, [NSError errorWithDomain:ATZShellErrorDomain code:ATZShellTerminationStatusError userInfo:userInfo]);
}
}];
Expand Down

0 comments on commit 2864836

Please sign in to comment.