Moved Cocoa error reporting to Github mode.

This commit is contained in:
Virgil Dupras 2014-03-30 10:07:01 -04:00
parent 10d1363334
commit 7d107d8efa
7 changed files with 56 additions and 48 deletions

View File

@ -14,7 +14,7 @@ class PyDupeGuruBase(PyBaseApp):
@dontwrap @dontwrap
def _init(self, modelclass): def _init(self, modelclass):
logging.basicConfig(level=logging.WARNING, format='%(levelname)s %(message)s') logging.basicConfig(level=logging.WARNING, format='%(levelname)s %(message)s')
install_exception_hook() install_exception_hook('https://github.com/hsoft/dupeguru/issues')
install_cocoa_logger() install_cocoa_logger()
patch_threaded_job_performer() patch_threaded_job_performer()
self.model = modelclass(self) self.model = modelclass(self)

View File

@ -11,14 +11,16 @@ http://www.hardcoded.net/licenses/bsd_license
@interface HSErrorReportWindow : NSWindowController @interface HSErrorReportWindow : NSWindowController
{ {
NSTextView *contentTextView; NSTextView *contentTextView;
NSString *githubUrl;
} }
@property (readwrite, retain) NSTextView *contentTextView; @property (readwrite, retain) NSTextView *contentTextView;
@property (readwrite, retain) NSString *githubUrl;
// True if the user wants to send the report // True if the user wants to send the report
+ (BOOL)showErrorReportWithContent:(NSString *)content; + (void)showErrorReportWithContent:(NSString *)content githubUrl:(NSString *)githubUrl;
- (id)initWithContent:(NSString *)content; - (id)initWithContent:(NSString *)content githubUrl:(NSString *)githubUrl;
- (void)send; - (void)goToGithub;
- (void)dontSend; - (void)close;
@end @end

View File

@ -12,33 +12,33 @@ http://www.hardcoded.net/licenses/bsd_license
@implementation HSErrorReportWindow @implementation HSErrorReportWindow
@synthesize contentTextView; @synthesize contentTextView;
@synthesize githubUrl;
+ (BOOL)showErrorReportWithContent:(NSString *)content + (void)showErrorReportWithContent:(NSString *)content githubUrl:(NSString *)githubUrl
{ {
HSErrorReportWindow *report = [[HSErrorReportWindow alloc] initWithContent:content]; HSErrorReportWindow *report = [[HSErrorReportWindow alloc] initWithContent:content githubUrl:githubUrl];
NSInteger result = [NSApp runModalForWindow:[report window]]; [NSApp runModalForWindow:[report window]];
[report release]; [report release];
return result == NSOKButton;
} }
- (id)initWithContent:(NSString *)content - (id)initWithContent:(NSString *)content githubUrl:(NSString *)aGithubUrl
{ {
self = [super initWithWindow:nil]; self = [super initWithWindow:nil];
[self setWindow:createHSErrorReportWindow_UI(self)]; [self setWindow:createHSErrorReportWindow_UI(self)];
[contentTextView alignLeft:nil]; [contentTextView alignLeft:nil];
[[[contentTextView textStorage] mutableString] setString:content]; [[[contentTextView textStorage] mutableString] setString:content];
self.githubUrl = aGithubUrl;
return self; return self;
} }
- (void)send - (void)goToGithub
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:self.githubUrl]];
}
- (void)close
{ {
[[self window] orderOut:self]; [[self window] orderOut:self];
[NSApp stopModalWithCode:NSOKButton]; [NSApp stopModalWithCode:NSOKButton];
} }
- (void)dontSend
{
[[self window] orderOut:self];
[NSApp stopModalWithCode:NSCancelButton];
}
@end @end

View File

@ -28,7 +28,7 @@
- (NSString *)url2path:(NSString *)url; - (NSString *)url2path:(NSString *)url;
- (void)createPool; - (void)createPool;
- (void)destroyPool; - (void)destroyPool;
- (BOOL)reportCrash:(NSString *)crashReport; - (void)reportCrash:(NSString *)crashReport withGithubUrl:(NSString *)githubUrl;
- (void)log:(NSString *)s; - (void)log:(NSString *)s;
- (NSDictionary *)readExifData:(NSString *)imagePath; - (NSDictionary *)readExifData:(NSString *)imagePath;
@end @end

View File

@ -143,9 +143,9 @@
} }
} }
- (BOOL)reportCrash:(NSString *)crashReport - (void)reportCrash:(NSString *)crashReport withGithubUrl:(NSString *)githubUrl
{ {
return [HSErrorReportWindow showErrorReportWithContent:crashReport]; return [HSErrorReportWindow showErrorReportWithContent:crashReport githubUrl:githubUrl];
} }
- (void)log:(NSString *)s - (void)log:(NSString *)s

View File

@ -11,7 +11,6 @@ import time
import traceback import traceback
import sys import sys
from hscommon.error_report import send_error_report
from .CocoaProxy import CocoaProxy from .CocoaProxy import CocoaProxy
proxy = CocoaProxy() proxy = CocoaProxy()
@ -81,21 +80,20 @@ def safe_format_exception(type, value, tb):
result.extend(traceback.format_exception_only(type, value)) result.extend(traceback.format_exception_only(type, value))
return result return result
def report_crash(type, value, tb): def install_exception_hook(github_url):
app_identifier = proxy.bundleIdentifier() def report_crash(type, value, tb):
app_version = proxy.appVersion() app_identifier = proxy.bundleIdentifier()
osx_version = proxy.osxVersion() app_version = proxy.appVersion()
s = "Application Identifier: {}\n".format(app_identifier) osx_version = proxy.osxVersion()
s += "Application Version: {}\n".format(app_version) s = "Application Identifier: {}\n".format(app_identifier)
s += "Mac OS X Version: {}\n\n".format(osx_version) s += "Application Version: {}\n".format(app_version)
s += ''.join(safe_format_exception(type, value, tb)) s += "Mac OS X Version: {}\n\n".format(osx_version)
if LOG_BUFFER: s += ''.join(safe_format_exception(type, value, tb))
s += '\nRelevant Console logs:\n\n' if LOG_BUFFER:
s += '\n'.join(LOG_BUFFER) s += '\nRelevant Console logs:\n\n'
if proxy.reportCrash_(s): s += '\n'.join(LOG_BUFFER)
send_error_report(s) proxy.reportCrash_withGithubUrl_(s, github_url)
def install_exception_hook():
sys.excepthook = report_crash sys.excepthook = report_crash
# A global log buffer to use for error reports # A global log buffer to use for error reports

View File

@ -1,33 +1,41 @@
ownerclass = 'HSErrorReportWindow' ownerclass = 'HSErrorReportWindow'
ownerimport = 'HSErrorReportWindow.h' ownerimport = 'HSErrorReportWindow.h'
result = Window(524, 390, "Error Report") result = Window(524, 470, "Error Report")
result.canClose = False result.canClose = False
result.canResize = False result.canResize = False
result.canMinimize = False result.canMinimize = False
label1 = Label(result, "Something went wrong. Would you like to send the error report to Hardcoded Software?") label1 = Label(result, "Something went wrong. How about reporting the error?")
errorTextView = TextView(result) errorTextView = TextView(result)
label2 = Label(result, "Although the application should continue to run after this error, it may be in an instable state, so it is recommended that you restart the application.") label2 = Label(result,
sendButton = Button(result, "Send") "Error reports should be reported as Github issues. You can copy the error traceback "
dontSendButton = Button(result, "Don't Send") "above and paste it in a new issue (bonus point if you run a search to make sure the "
"issue doesn't already exist). What usually really helps is if you add a description "
"of how you got the error. Thanks!"
"\n\n"
"Although the application should continue to run after this error, it may be in an "
"unstable state, so it is recommended that you restart the application."
)
sendButton = Button(result, "Go to Github")
dontSendButton = Button(result, "Close")
owner.contentTextView = errorTextView owner.contentTextView = errorTextView
sendButton.action = Action(owner, 'send') sendButton.action = Action(owner, 'goToGithub')
sendButton.keyEquivalent = "\\r" sendButton.keyEquivalent = "\\r"
dontSendButton.action = Action(owner, 'dontSend') dontSendButton.action = Action(owner, 'close')
dontSendButton.keyEquivalent = "\\E" dontSendButton.keyEquivalent = "\\E"
label1.height = 34 label1.height = 34
errorTextView.height = 221 errorTextView.height = 221
label2.height = 51 label2.height = 130
sendButton.width = 100 sendButton.width = 100
dontSendButton.width = 100 dontSendButton.width = 100
label1.packToCorner(Pack.UpperLeft) label1.moveTo(Pack.UpperLeft)
label1.fill(Pack.Right) label1.fill(Pack.Right)
errorTextView.packRelativeTo(label1, Pack.Below, Pack.Left) errorTextView.moveNextTo(label1, Pack.Below, Pack.Left)
errorTextView.fill(Pack.Right) errorTextView.fill(Pack.Right)
label2.packRelativeTo(errorTextView, Pack.Below, Pack.Left) label2.moveNextTo(errorTextView, Pack.Below, Pack.Left)
label2.fill(Pack.Right) label2.fill(Pack.Right)
sendButton.packRelativeTo(label2, Pack.Below, Pack.Right) sendButton.moveNextTo(label2, Pack.Below, Pack.Right)
dontSendButton.packRelativeTo(sendButton, Pack.Left, Pack.Middle) dontSendButton.moveNextTo(sendButton, Pack.Left, Pack.Middle)