diff --git a/cocoalib/HSErrorReportWindow.h b/cocoalib/HSErrorReportWindow.h index 0aa59fde..7c914c50 100644 --- a/cocoalib/HSErrorReportWindow.h +++ b/cocoalib/HSErrorReportWindow.h @@ -15,7 +15,8 @@ http://www.hardcoded.net/licenses/bsd_license @property (readwrite, retain) NSTextView *contentTextView; -+ (void)showErrorReportWithContent:(NSString *)content; +// True if the user wants to send the report ++ (BOOL)showErrorReportWithContent:(NSString *)content; - (id)initWithContent:(NSString *)content; - (void)send; diff --git a/cocoalib/HSErrorReportWindow.m b/cocoalib/HSErrorReportWindow.m index fadc4455..91c2d820 100644 --- a/cocoalib/HSErrorReportWindow.m +++ b/cocoalib/HSErrorReportWindow.m @@ -13,11 +13,12 @@ http://www.hardcoded.net/licenses/bsd_license @synthesize contentTextView; -+ (void)showErrorReportWithContent:(NSString *)content ++ (BOOL)showErrorReportWithContent:(NSString *)content { HSErrorReportWindow *report = [[HSErrorReportWindow alloc] initWithContent:content]; - [NSApp runModalForWindow:[report window]]; + NSInteger result = [NSApp runModalForWindow:[report window]]; [report release]; + return result == NSOKButton; } - (id)initWithContent:(NSString *)content @@ -31,11 +32,6 @@ http://www.hardcoded.net/licenses/bsd_license - (void)send { - NSString *text = [[contentTextView textStorage] string]; - NSString *URL = [NSString stringWithFormat:@"mailto:support@hardcoded.net?SUBJECT=Error Report&BODY=%@",text]; - NSString *encodedURL = [URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:encodedURL]]; - [[self window] orderOut:self]; [NSApp stopModalWithCode:NSOKButton]; } diff --git a/cocoalib/cocoa/CocoaProxy.h b/cocoalib/cocoa/CocoaProxy.h index 58614550..4e9fdaac 100644 --- a/cocoalib/cocoa/CocoaProxy.h +++ b/cocoalib/cocoa/CocoaProxy.h @@ -28,7 +28,7 @@ - (NSString *)url2path:(NSString *)url; - (void)createPool; - (void)destroyPool; -- (void)reportCrash:(NSString *)crashReport; +- (BOOL)reportCrash:(NSString *)crashReport; - (void)log:(NSString *)s; - (NSDictionary *)readExifData:(NSString *)imagePath; @end \ No newline at end of file diff --git a/cocoalib/cocoa/CocoaProxy.m b/cocoalib/cocoa/CocoaProxy.m index 6610dbed..78cac95a 100644 --- a/cocoalib/cocoa/CocoaProxy.m +++ b/cocoalib/cocoa/CocoaProxy.m @@ -143,9 +143,9 @@ } } -- (void)reportCrash:(NSString *)crashReport +- (BOOL)reportCrash:(NSString *)crashReport { - [HSErrorReportWindow showErrorReportWithContent:crashReport]; + return [HSErrorReportWindow showErrorReportWithContent:crashReport]; } - (void)log:(NSString *)s diff --git a/cocoalib/cocoa/__init__.py b/cocoalib/cocoa/__init__.py index e56d9a0f..33d09805 100644 --- a/cocoalib/cocoa/__init__.py +++ b/cocoalib/cocoa/__init__.py @@ -12,6 +12,7 @@ import traceback import subprocess import sys +from hscommon.error_report import send_error_report from .CocoaProxy import CocoaProxy proxy = CocoaProxy() @@ -97,7 +98,8 @@ def report_crash(type, value, tb): except IndexError: # This can happen if something went wrong with the grep (permission errors?) pass - proxy.reportCrash_(s) + if proxy.reportCrash_(s): + send_error_report(s) def install_exception_hook(): sys.excepthook = report_crash diff --git a/hscommon/error_report.py b/hscommon/error_report.py index 82ee3973..f73ffc1e 100644 --- a/hscommon/error_report.py +++ b/hscommon/error_report.py @@ -10,14 +10,18 @@ import ftplib import io import time import threading +import logging def send_error_report(text): def do(): - conn = ftplib.FTP('drop.hardcoded.net') - conn.login() - conn.cwd('/drop') - textfp = io.BytesIO(text.encode('utf-8')) - cmd = 'STOR report%d.txt' % time.time() - conn.storbinary(cmd, textfp) + try: + conn = ftplib.FTP('drop.hardcoded.net') + conn.login() + conn.cwd('/drop') + textfp = io.BytesIO(text.encode('utf-8')) + cmd = 'STOR report%d.txt' % time.time() + conn.storbinary(cmd, textfp) + except Exception as e: + logging.warning("Couldn't send error report: %s", e) threading.Thread(target=do).start()