<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">Begin forwarded message:</div><br class="Apple-interchange-newline"><blockquote type="cite" class=""><p style="margin: 0.0px 0.0px 0.0px 40.8px; text-indent: -40.8px" class=""><font face=".AppleSystemUIFont" size="4" color="#000000" style="font: 14.0px '.AppleSystemUIFont'; color: #000000" class="">From: Jon Shier <<a href="mailto:jon@jonshier.com" class="">jon@jonshier.com</a>></font></p>
<p style="margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px" class=""><font face=".AppleSystemUIFont" size="4" color="#000000" style="font: 14.0px '.AppleSystemUIFont'; color: #000000" class="">Subject: Re: [swift-users] intercept fatalError() or other termination messages from swift?</font></p>
<p style="margin: 0.0px 0.0px 0.0px 38.1px; text-indent: -38.1px" class=""><font face=".AppleSystemUIFont" size="4" color="#000000" style="font: 14.0px '.AppleSystemUIFont'; color: #000000" class="">Date: June 26, 2017 at 12:30:50 PM PDT</font></p>
<p style="margin: 0.0px 0.0px 0.0px 23.6px; text-indent: -23.6px" class=""><font face=".AppleSystemUIFont" size="4" color="#000000" style="font: 14.0px '.AppleSystemUIFont'; color: #000000" class="">To: David Baraff <<a href="mailto:davidbaraff@gmail.com" class="">davidbaraff@gmail.com</a>></font></p>
<p style="margin: 0.0px 0.0px 0.0px 25.4px; text-indent: -25.4px" class=""><font face=".AppleSystemUIFont" size="4" color="#000000" style="font: 14.0px '.AppleSystemUIFont'; color: #000000" class="">Cc: Joe Groff <<a href="mailto:jgroff@apple.com" class="">jgroff@apple.com</a>>, swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>></font></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; min-height: 14.0px" class=""><br class=""></p>
</blockquote><blockquote type="cite" class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class="">If you export the crash from Xcode, do you see the string in the raw report?</blockquote><div class=""><br class=""></div>No.<div class=""><br class=""><blockquote type="cite" class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Jon</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jun 26, 2017, at 3:22 PM, David Baraff via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">To be very clear, i’m concerned about iOS not mac os x. I pulled up a crash report using xcode tools, and saw no mention of the string output by fatal error. If there is someway after the fact of, on an iPhone or iOS interogating the asl_log when you restart your program to glean the error message, i’m all ears.<div class=""><br class=""></div><div class=""><br class=""><div class=""><div class=""><blockquote type="cite" class=""><div class="">On Jun 26, 2017, at 10:01 AM, Joe Groff <<a href="mailto:jgroff@apple.com" class="">jgroff@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jun 23, 2017, at 9:13 PM, David Baraff via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">I realize this is slightly centric to iOS, but it irks me that both Apple’s crash report logs and popular platforms like PLCrashReporter can do the hard stuff like give you a stack trace, but are *completely* unable to display the error message from terminating a program via fatalError(), or the error message from, e.g. dying with a bad optional.<br class=""><br class="">Is there *any* to intercept the error messages that from fatalError() and similar like things in swift (bad optionals, invalid array accesses, assertions)? I would think that some sort of a “hook” into these standard error routines would be a good thing.<br class=""><br class="">In my case, if I could simply save that darn error string in a file, i could pick it up when the app next launches and report it along with the rest of the info like the stack/signal, etc.<br class=""><br class="">I’ve been looking through the code in stdlib/public/runtime/Errors.cpp but haven’t found anything promising that lets me jump in there. In my code, I’m likely to write things like<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>guard let x = … else {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>fatalError(“Data type has payload <T> but is hooked to UI control with intrinsic type <U>”)<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}<br class=""><br class="">and having that exact string tells me precisely what’s going, far simpler than a stack trace.<br class=""></div></div></blockquote></div><br class=""><div class=""><br class=""></div><div class="">Fatal error messages already get logged three ways:</div><div class=""><br class=""></div><div class="">- Printed to the process's stderr;</div><div class="">- Logged to the system log using asl_log;</div><div class="">- Set as the crash reason for CrashReporter.</div><div class=""><br class=""></div><div class="">The crash messages should thus already be in your crash reports somewhere. See <a href="https://github.com/jckarter/swift/blob/master/stdlib/public/runtime/Errors.cpp#L168" class="">https://github.com/jckarter/swift/blob/master/stdlib/public/runtime/Errors.cpp#L168</a> and <a href="https://github.com/jckarter/swift/blob/master/stdlib/public/runtime/Errors.cpp#L204" class="">https://github.com/jckarter/swift/blob/master/stdlib/public/runtime/Errors.cpp#L204</a> for the relevant runtime source code. cc'ing Greg Parker who probably knows better exactly where these messages end up.</div><div class=""><br class=""></div><div class="">-Joe</div></div></div></blockquote></div><br class=""></div></div></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></div></blockquote></div><br class=""></div></blockquote></div></body></html>