Question

I'm developing an app on Mac OS X which is suspected to crash sometimes (well, not due to my app, but due to unstable third-party plug-ins it loads. This app actually acts as a crash firewall; many crashes can happen at startup, so no need to bug the user about it at this time).

Is there a way to prevent the crash report window from popping in front of the user?

Thanks!

PS: this is about this window, but not for WebKit: A crash reporting window on Mac OS X

Was it helpful?

Solution

I'm not aware of any really supported solution, but there are some (ugly) ways to achieve it.

First, you need to catch the signal yourself. I assume you know how to do that (see sigaction). Then within your crash signal handler, call _exit(). That's with a leading underscore. It's a faster, less safe version of exit(). This will typically avoid the crash reporter. I've used this in some C++ projects that had such flakey memory management that they often crashed on shutdown. I'm not proud of it; I'm just saying it works....

The other solution is to launch another second process during your crash handler. The second process waits around for CrashReporter to launch. When it does, kill it. The last time I tested this approach was 10.5. I don't know if 10.7 still launches the same kind of process to display that alert.

OTHER TIPS

For a system-wide solution, read man ReportCrash. However this solution is not specific to an application.

Using cli Swift 4.2.1

Building on Rob Napier's answer.
I don't know how signal(3) becomes Darwin.signal(_:Int32,_:@convention(c)(Int32)->()) but the following actually works (preventing reporter for uncaught NSException), whereas temporarily doing and reverting defaults write com.apple.CrashReporter DialogType none && defaults write com.apple.CrashReporter UseUNC 1 (from osxdaily.com 2010 & 2015) (on my macOS 10.13) does not work.

import Darwin
signal(SIGABRT  ){n in _exit(128+n)}

(Using Bash(1) signal exit(3) convention.)


Moving on, I find "Unexpectedly found nil"-errors (from implicit unwrapping in my case) uses another signal:

signal(SIGILL   ){n in _exit(128+n)}

This also skips the builtin call stack printing and though it doesn't show where the nil's found anyway, a variant can be printed by the following:

import Darwin
import Foundation
Thread.callStackSymbols.forEach{fputs($0+"\n",stderr)}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top