From 2864836f3507d143766faa4c4ab71ab70e4ad46c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ce=CC=81dric=20Luthi?= Date: Thu, 2 Jun 2016 19:34:30 +0200 Subject: [PATCH] Truncate error only when presenting it --- Alcatraz/Controllers/ATZPluginWindowController.m | 12 ++++++++++++ Alcatraz/Helpers/ATZShell.m | 4 +--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Alcatraz/Controllers/ATZPluginWindowController.m b/Alcatraz/Controllers/ATZPluginWindowController.m index f50703a..94483eb 100644 --- a/Alcatraz/Controllers/ATZPluginWindowController.m +++ b/Alcatraz/Controllers/ATZPluginWindowController.m @@ -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 { diff --git a/Alcatraz/Helpers/ATZShell.m b/Alcatraz/Helpers/ATZShell.m index ada92b7..1d07003 100644 --- a/Alcatraz/Helpers/ATZShell.m +++ b/Alcatraz/Helpers/ATZShell.m @@ -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]); } }];