Today's lesson in not using Apple's private methods: somewhere between old/886f95f00431 and #9620 Apple changed their document icon setup process. Use the new methods and fix #9620.
(transplanted from 5cf365ce9352d25978ffd6073d3bc07573aba518)
/*
* Adium is the legal property of its developers, whose names are listed in the copyright file included
* with this source distribution.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import "AICrashReporter.h"
#import "AIExceptionController.h"
#import <AIUtilities/AIFileManagerAdditions.h>
#import <AIUtilities/AIStringAdditions.h>
#import <ExceptionHandling/NSExceptionHandler.h>
#include<unistd.h>
/*!
* @class AIExceptionController
* @brief Catches application exceptions and forwards them to the crash reporter application
*
* Once configured, sets itself as the NSExceptionHandler delegate to decode the stack traces
* generated via NSExceptionHandler, write them to a file, and launch the crash reporter.
*/
@implementationAIExceptionController
//Enable exception catching for the crash reporter
@"_sharedInstance is invalid.",//Address book framework is weird sometimes
@"No text was found",//ICeCoffEE is an APE haxie which would crash us whenever a user pasted, or something like that
@"No URL is selected",//ICeCoffEE also crashes us when clicking links. How obnoxious. Release software should not use NSAssert like this.
#warning Error 1000 is kCGErrorFirst. This special case was added in r5425, so long ago that it's possible that this was really supposed to be 1007, and has been fixed since then.
@"Error (1000) creating CGSWindow",//This looks like an odd NSImage error... it occurs sporadically, seems harmless, and doesn't appear avoidable
@"Error (1007) creating CGSWindow",//kCGErrorRangeCheck: Raised by NSImage when we create one that's bigger than a window can hold. See <http://www.cocoabuilder.com/archive/message/cocoa/2004/2/5/96193>.
@"Access invalid attribute location 0 (length 0)",//The undo manager can throw this one when restoring a large amount of attributed text... doesn't appear avoidable
@"Invalid parameter not satisfying: (index >= 0) && (index < (_itemArray ? CFArrayGetCount(_itemArray) : 0))",//A couple AppKit methods, particularly NSSpellChecker, seem to expect this exception to be happily thrown in the normal course of operation. Lovely. Also needed for FontSight compatibility.
@"Invalid parameter not satisfying: (index >= 0) && (index <= (_itemArray ? CFArrayGetCount(_itemArray) : 0))",//Like the above, but <= instead of <
@"Invalid parameter not satisfying: entry",//NSOutlineView throws this, particularly if it gets clicked while reloading or the computer sleeps while reloading
@"Invalid parameter not satisfying: aString != nil",//The Find command can throw this, as can other AppKit methods
nil];
}
if(!safeExceptionNames){
safeExceptionNames=[[NSSetalloc]initWithObjects:
@"GIFReadingException",//GIF reader sucks
@"NSPortTimeoutException",//Harmless - it timed out for a reason
@"NSInvalidReceivePortException",//Same story as NSPortTimeoutException
@"NSAccessibilityException",//Harmless - one day we should figure out how we aren't accessible, but not today
@"NSImageCacheException",//NSImage is silly
@"NSArchiverArchiveInconsistency",//Odd system hacks can lead to this one
@"NSUnknownKeyException",//No reason to crash on invalid Applescript syntax
@"NSObjectInaccessibleException",//We don't use DO, but spell checking does; AppleScript execution requires multiple run loops, and the HIToolbox can get confused and try to spellcheck in the applescript thread. Silly Apple.
@"NSCharacterConversionException",//We can't help it if a character can't be converted...
@"NSRTFException",//Better to ignore than to crash
nil];
}
}
// mask is NSHandle<exception type>Mask, exception's userInfo has stack trace for key NSStackTraceKey
//Ignore various known harmless or unavoidable exceptions (From the system or system hacks)
if((!theReason)||//Harmless
[safeExceptionReasonscontainsObject:theReason]||
[theReasonrangeOfString:@"NSRunStorage, _NSBlockNumberForIndex()"].location!=NSNotFound||//NSLayoutManager throws this for fun in a purely-AppKit stack trace
[theReasonrangeOfString:@"Broken pipe"].location!=NSNotFound||//libezv throws broken pipes as NSFileHandleOperationException with this in the reason; I'd rather we watched for "broken pipe" than ignore all file handle errors
[theReasonrangeOfString:@"incomprehensible archive"].location!=NSNotFound||//NSKeyedUnarchiver can get confused and throw this; it's out of our control
[theReasonrangeOfString:@"-whiteComponent not defined"].location!=NSNotFound||//Random NSColor exception for certain coded color values
[theReasonrangeOfString:@"Failed to get fache"].location!=NSNotFound||//Thrown by NSFontManager when availableFontFamilies is called if it runs into a corrupt font
[theReasonrangeOfString:@"NSWindow: -_newFirstResponderAfterResigining"].location!=NSNotFound||//NSAssert within system code, harmless
[theReasonrangeOfString:@"-patternImage not defined"].location!=NSNotFound||//Painters Color Picker throws an exception during the normal course of operation. Don't you hate that?
[theReasonrangeOfString:@"Failed to set font"].location!=NSNotFound||//Corrupt fonts
[theReasonrangeOfString:@"Delete invalid attribute range"].location!=NSNotFound||//NSAttributedString's initWithCoder can throw this
[theReasonrangeOfString:@"NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds"].location!=NSNotFound||//-[NSLayoutManager textContainerForGlyphAtIndex:effectiveRange:] as of 10.4 can throw this
[theReasonrangeOfString:@"TSMProcessRawKeyCode failed"].location!=NSNotFound||//May be raised by -[NSEvent charactersIgnoringModifiers]
[theReasonrangeOfString:@"Invalid PMPrintSettings in print info"].location!=NSNotFound||//Invalid saved print settings can make the print dialogue throw this
[theReasonrangeOfString:@"-[NSConcreteTextStorage attribute:atIndex:effectiveRange:]: Range or index out of bounds"].location!=NSNotFound||//Can't find the source of this, but it seems to happen randomly and not provide a stack trace.
[theReasonrangeOfString:@"SketchUpColor"].location!=NSNotFound||//NSColorSwatch addition which can yield an exception
[theReasonrangeOfString:@"-[NSConcreteFileHandle dealloc]: Bad file descriptor"].location!=NSNotFound||// NSFileHandle on an invalid file descriptor should log but not crash
(!theName)||//Harmless
[theNamerangeOfString:@"RSS"].location!=NSNotFound||//Sparkle's RSS handling whines sometimes, but we don't care.
[safeExceptionNamescontainsObject:theName])
{
shouldLaunchCrashReporter=NO;
}
//Check the stack trace for a third set of known offenders
if(shouldLaunchCrashReporter){
backtrace=[exceptiondecodedExceptionStackTrace];
}
if(!backtrace||
[backtracerangeOfString:@"-[NSFontPanel setPanelFont:isMultiple:] (in AppKit)"].location!=NSNotFound||//NSFontPanel likes to create exceptions
[backtracerangeOfString:@"-[NSScrollView(NSScrollViewAccessibility) accessibilityChildrenAttribute]"].location!=NSNotFound||//Perhaps we aren't implementing an accessibility method properly? No idea what though :(
[backtracerangeOfString:@"-[WebBridge objectLoadedFromCacheWithURL:response:data:]"].location!=NSNotFound||//WebBridge throws this randomly it seems
[backtracerangeOfString:@"-[NSTextView(NSSharing) _preflightSpellChecker:]"].location!=NSNotFound||//Systemwide spell checker gets corrupted on some systems; other apps just end up logging to console, and we should do the same.
[backtracerangeOfString:@"-[NSFontManager(NSFontManagerCollectionAdditions) _collectionsChanged:]"].location!=NSNotFound||//Deleting an empty collection in 10.4.3 (and possibly other versions) throws an NSRangeException with this in the backtrace.
[backtracerangeOfString:@"[NSSpellChecker sharedSpellChecker]"].location!=NSNotFound//The spell checker screws up and starts throwing an exception on every word on many people's systems.