Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I get assertion messages into crash logs in Swift

Tags:

swift

so - I use guards and assertions all over the place - I just added a check for something like this:

if start == end 
{
    fatalError( "can't initialise a date range of zero size but start and end are both \(start)")
}

and it dies correctly - but in my crash report I just see:

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libswiftCore.dylib                     0x10a61483b _assertionFailure(_:_:file:line:flags:) + 427
1   Weight Waist and Fat                   0x102669179 Date_range.init(start:end:) + 1321 (Date_range.swift:42)
...

the word "initialise" doesn't appear anywhere in the entire crash report. How do I put in assertions where I actually get the information I need - do I have to set something? Is fatalError the wrong thing to be using?

like image 843
Darren Oakey Avatar asked Nov 15 '25 04:11

Darren Oakey


1 Answers

The information you want is being pruned for privacy reasons.

https://forums.swift.org/t/intercept-fatalerror-or-other-termination-messages-from-swift/6190

You might be better off throwing an NSException via Objective-C if you insist on having this in the crash log. Personally I just write into the log file with OSLog and pick up the info with the sudo log tool later.

like image 95
matt Avatar answered Nov 17 '25 20:11

matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!