-
-
Notifications
You must be signed in to change notification settings - Fork 317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fatalError call with message does not report message value in Sentry Dashboard #662
Comments
Thanks, @martindufort for opening this issue. I can easily reproduce this issue. Calling |
Thanks for validating this @philipphofmann. I've written a workaround function called
|
@philipphofmann It's possible to extract this information from the Apple Crash Reporting section in some cases. A collection of information on this can be found here: https://bugzilla.mozilla.org/show_bug.cgi?id=1577886 You can see it in action in the code, e.g. https://github.com/apple/swift/blob/6527a216fb2f0264f5009cda379c961ebf59fe65/stdlib/public/runtime/Errors.cpp#L363 |
Thanks, @sammydre for the information. |
This post summararizes different resources from the web and investigations. Application Specific Information macOS
iOS
According to a post in Bugzilla, an article from Alastair's Place and an issue on KSCrash #define CRASH_ALIGN __attribute__((aligned(8)))
typedef struct {
unsigned version CRASH_ALIGN;
const char *message CRASH_ALIGN;
const char *signature CRASH_ALIGN;
const char *backtrace CRASH_ALIGN;
const char *message2 CRASH_ALIGN;
void *reserved CRASH_ALIGN;
void *reserved2 CRASH_ALIGN;
} crash_info_t;
unsigned long size = 0;
crash_info_t* infoPtr = (crash_info_t*)getsectdatafromFramework("AppKit", SEG_DATA, "__crash_info", &size); I put this code into
All the other fields of crash info are null. Competition:
Logs
Also device console logs display fatal error messages: This means that Xcode and the device console can somehow catch the message from somewhere. Swift Compiler
Other relevant resources:
|
We did some research into this at work and unfortunately haven't found the time to write it all up, but I thought it might be helpful to mention some of the pieces here.
The example code I had to look for crash reasons was as follows: #define CRASH_ALIGN __attribute__((aligned(8)))
typedef struct {
unsigned version CRASH_ALIGN;
const char *message CRASH_ALIGN;
const char *signature CRASH_ALIGN;
const char *backtrace CRASH_ALIGN;
const char *message2 CRASH_ALIGN;
void *reserved CRASH_ALIGN;
void *reserved2 CRASH_ALIGN;
} crash_info_t;
void dumpCrashReports()
{
const unsigned images_count = _dyld_image_count();
for (unsigned i = 0; i < images_count; i++) {
const char *name = _dyld_get_image_name(i);
const struct mach_header* header = _dyld_get_image_header(i);
if (!header) {
fprintf(stderr, "image %02d: (%s) null\n", i, name);
continue;
}
#if 1 // 64-bit
uint64_t size = 0;
char* data_ptr = getsectdatafromheader_64(
(const struct mach_header_64*)(header),
SEG_DATA,
"__crash_info",
&size);
#else
unsigned int size;
char* code_ptr = getsectdatafromheader(header, SEG_TEXT, SECT_TEXT, &size);
#endif
data_ptr += _dyld_get_image_vmaddr_slide(i);
fprintf(stderr, "image %02d: (%s) ptr %p size %lu\n", i, name, data_ptr, size);
if (data_ptr && size) {
crash_info_t *cr = (crash_info_t *)data_ptr;
fprintf(stderr, " version %u message %s signature %s backtrace %s message2 %s\n",
cr->version, cr->message, cr->signature, cr->backtrace, cr->message2);
}
}
} Hope that is helpful @philipphofmann . If it is possible to get the crash info without needing to change the assert compilation mode, that would obviously be superior, but I'd argue the approach I've outlined here would be sufficient for many users. |
To further elaborate on what the Swift compiler does here: Swift compiler version:
Example file that crashes via an unwrap:
Compiler output with Debug -- note the call to
Compiler output in Release -- note how it just goes to an
|
Thanks a lot for the detailed explanation @sammydre 👏. I should have iterated over all the images and look for the This only works for asserts in release, if you have them enabled, of course, but it seems like this should work for Example with func sample() {
fatalError("Won't work")
} Debug
Release
|
This issue has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you label it "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
The SDK was not able to retrieve the messages from Swifts fatalError, assert, or precondition.This is fixed now by getting the message from the crashInfoMessage of the binary image of libswiftCore.dylib. Fixes GH-662
The SDK was not able to retrieve the messages from Swifts fatalError, assert, or precondition.This is fixed now by getting the message from the crashInfoMessage of the binary image of libswiftCore.dylib. Fixes GH-662
The SDK was not able to retrieve the messages from Swifts fatalError, assert, or precondition.This is fixed now by getting the message from the crashInfoMessage of the binary image of libswiftCore.dylib. Fixes GH-662
The SDK was not able to retrieve the messages from Swifts fatalError, assert, or precondition.This is fixed now by getting the message from the crashInfoMessage of the binary image of libswiftCore.dylib. Fixes GH-662
The SDK was not able to retrieve the messages from Swifts fatalError, assert, or precondition. This is fixed now by getting the message from the crashInfoMessage of the binary image of libswiftCore.dylib. Fixes GH-662 Co-authored-by: Dhiogo Brustolin <[email protected]>
Important Details
How are you running Sentry?
Saas (sentry.io)
Description
In macOS Swift app, using
fatalError(message:String)
to report an abnormal condition.Error is reported within the Sentry dashboard but the message is not displayed anywhere.
Steps to Reproduce
This is the code that produced this error:
What you expected to happen
The relevant message
Forcing a crash within the Advanced Preferences section
should be captured and displayed in the dashboard.Please review event: https://sentry.io/share/issue/68d48cf4f07440cbad16a672580f9cae/
The text was updated successfully, but these errors were encountered: