Skip to content

Commit

Permalink
Merge branch 'master' into feat/item-iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
limbonaut committed Feb 14, 2025
2 parents 1accd89 + 011e705 commit 05b907e
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 22 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ ColumnLimit: 80
AlwaysBreakAfterDefinitionReturnType: All
PointerAlignment: Right
ForEachMacros: ['SENTRY_WITH_SCOPE', 'SENTRY_WITH_SCOPE_MUT', 'SENTRY_WITH_SCOPE_MUT_NO_FLUSH', 'SENTRY_WITH_OPTIONS', 'SENTRY_WITH_OPTIONS_MUT']
InsertNewlineAtEOF: True
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@

## Unreleased

**Breaking changes**:

- Return type of `sentry_capture_minidump()` and `sentry_capture_minidump_n()` changed from `void` to `sentry_uuid_t` to retrieve the event-id for a successful minidump upload. ([#1138](https://github.com/getsentry/sentry-native/pull/1138))

**Features**:

- Add object item iterators. ([#1143](https://github.com/getsentry/sentry-native/pull/1143))

**Fixes**:

- Ensure that `sentry_capture_minidump()` fails if the provided minidump path cannot be attached, instead of sending a crash event without minidump. ([#1138](https://github.com/getsentry/sentry-native/pull/1138))
- Fix Xbox OS name being reported incorrectly ([#1148](https://github.com/getsentry/sentry-native/pull/1148))

**Thank you**:

[zsd4yr](https://github.com/zsd4yr)

## 0.7.20

**Features**:
Expand Down
10 changes: 8 additions & 2 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -1457,9 +1457,15 @@ SENTRY_API sentry_uuid_t sentry_capture_event(sentry_value_t event);
* This generates a fatal error event, includes the scope and attachments.
* If the event isn't dropped by a before-send hook, the minidump is attached
* and the event is sent.
*
* Returns a nil `UUID` if capturing the minidump failed and the event-id
* otherwise. Uploads can fail because capturing is asynchronous, so a non-nil
* `UUID` is not a delivery guarantee. However, if the minidump is successfully
* delivered, the ID is guaranteed to be the same as the event in the Sentry UI.
*/
SENTRY_API void sentry_capture_minidump(const char *path);
SENTRY_API void sentry_capture_minidump_n(const char *path, size_t path_len);
SENTRY_API sentry_uuid_t sentry_capture_minidump(const char *path);
SENTRY_API sentry_uuid_t sentry_capture_minidump_n(
const char *path, size_t path_len);

/**
* Captures an exception to be handled by the backend.
Expand Down
48 changes: 30 additions & 18 deletions src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,7 @@ sentry__roll_dice(double probability)
sentry_uuid_t
sentry__capture_event(sentry_value_t event)
{
// `event_id` is only used as an argument to pure output parameters.
// Initialization only happens to prevent compiler warnings.
sentry_uuid_t event_id = sentry_uuid_nil();
sentry_uuid_t event_id;
sentry_envelope_t *envelope = NULL;

bool was_captured = false;
Expand Down Expand Up @@ -1257,40 +1255,45 @@ sentry_clear_crashed_last_run(void)
return success ? 0 : 1;
}

void
sentry_uuid_t
sentry_capture_minidump(const char *path)
{
sentry_capture_minidump_n(path, sentry__guarded_strlen(path));
return sentry_capture_minidump_n(path, sentry__guarded_strlen(path));
}

void
sentry_uuid_t
sentry_capture_minidump_n(const char *path, size_t path_len)
{
sentry_path_t *dump_path = sentry__path_from_str_n(path, path_len);

if (!dump_path) {
SENTRY_WARN(
"sentry_capture_minidump() failed due to null path to minidump");
return;
return sentry_uuid_nil();
}

SENTRY_DEBUGF(
"Capturing minidump \"%" SENTRY_PATH_PRI "\"", dump_path->path);

sentry_value_t event = sentry_value_new_event();
sentry_value_set_by_key(
event, "level", sentry__value_new_level(SENTRY_LEVEL_FATAL));

SENTRY_WITH_OPTIONS (options) {
sentry_uuid_t event_id;
sentry_value_t event = sentry_value_new_event();
sentry_value_set_by_key(
event, "level", sentry__value_new_level(SENTRY_LEVEL_FATAL));
sentry_envelope_t *envelope
= sentry__prepare_event(options, event, NULL, true);
= sentry__prepare_event(options, event, &event_id, true);

if (envelope) {
if (!envelope || sentry_uuid_is_nil(&event_id)) {
sentry_value_decref(event);
} else {
// the minidump is added as an attachment, with type
// `event.minidump`
sentry_envelope_item_t *item = sentry__envelope_add_from_path(
envelope, dump_path, "attachment");
if (item) {

if (!item) {
sentry_envelope_free(envelope);
} else {
sentry__envelope_item_set_header(item, "attachment_type",
sentry_value_new_string("event.minidump"));

Expand All @@ -1301,14 +1304,23 @@ sentry_capture_minidump_n(const char *path, size_t path_len)
sentry_value_new_string(
#endif
sentry__path_filename(dump_path)));
}

sentry__capture_envelope(options->transport, envelope);
sentry__capture_envelope(options->transport, envelope);

SENTRY_INFOF("Minidump has been captured: \"%" SENTRY_PATH_PRI
"\"",
dump_path->path);
sentry__path_free(dump_path);

SENTRY_INFOF("Minidump has been captured: \"%" SENTRY_PATH_PRI "\"",
dump_path->path);
sentry_options_free((sentry_options_t *)options);
return event_id;
}
}
}

SENTRY_WARNF(
"Minidump was not captured: \"%" SENTRY_PATH_PRI "\"", dump_path->path);
sentry__path_free(dump_path);

return sentry_uuid_nil();
}
3 changes: 3 additions & 0 deletions src/sentry_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ void sentry__logger_log(sentry_level_t level, const char *message, ...);

#define SENTRY_WARN(message) sentry__logger_log(SENTRY_LEVEL_WARNING, message)

#define SENTRY_ERRORF(message, ...) \
sentry__logger_log(SENTRY_LEVEL_ERROR, message, __VA_ARGS__)

#define SENTRY_ERROR(message) sentry__logger_log(SENTRY_LEVEL_ERROR, message)

#endif
2 changes: 1 addition & 1 deletion src/sentry_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ sentry__get_os_context(void)
# if defined(_GAMING_XBOX_SCARLETT)
# pragma warning(push)
# pragma warning(disable : 4996)
sentry_value_set_by_key(os, "name", sentry_value_new_string("Windows"));
sentry_value_set_by_key(os, "name", sentry_value_new_string("Xbox"));
OSVERSIONINFO os_ver = { 0 };
char buf[128];
buf[0] = 0;
Expand Down
63 changes: 63 additions & 0 deletions tests/unit/test_basic.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "sentry_core.h"
#include "sentry_database.h"
#include "sentry_string.h"
#include "sentry_testsupport.h"

static void
Expand Down Expand Up @@ -212,3 +213,65 @@ SENTRY_TEST(crashed_last_run)

TEST_CHECK_INT_EQUAL(sentry_get_crashed_last_run(), 0);
}

SENTRY_TEST(capture_minidump_basic)
{
#if defined(SENTRY_PLATFORM_ANDROID)
SKIP_TEST();
#else
sentry_options_t *options = sentry_options_new();
sentry_init(options);

const char *minidump_rel_path = "../fixtures/minidump.dmp";
sentry_path_t *path = sentry__path_from_str(__FILE__);
sentry_path_t *dir = sentry__path_dir(path);
sentry_path_t *minidump_path
= sentry__path_join_str(dir, minidump_rel_path);

# if defined(SENTRY_PLATFORM_WINDOWS)
char *path_str = sentry__string_from_wstr(minidump_path->path);
const sentry_uuid_t event_id = sentry_capture_minidump(path_str);
sentry_free(path_str);
# else
const sentry_uuid_t event_id = sentry_capture_minidump(minidump_path->path);
# endif
TEST_CHECK(!sentry_uuid_is_nil(&event_id));

sentry__path_free(minidump_path);
sentry__path_free(dir);
sentry__path_free(path);

sentry_close();
#endif
}

SENTRY_TEST(capture_minidump_null_path)
{
// a NULL path will activate the path check at the beginning of the function
const sentry_uuid_t event_id = sentry_capture_minidump(NULL);
TEST_CHECK(sentry_uuid_is_nil(&event_id));
}

SENTRY_TEST(capture_minidump_without_sentry_init)
{
// if the path initialization was successful, but the SDK wasn't initialized
// capturing will fail at the point of acquiring the active options.
const sentry_uuid_t event_id
= sentry_capture_minidump("irrelevant_minidump_path");
TEST_CHECK(sentry_uuid_is_nil(&event_id));
}

SENTRY_TEST(capture_minidump_invalid_path)
{
sentry_options_t *options = sentry_options_new();
sentry_init(options);

// here the initialization is successful, but we provide an invalid minidump
// path which should prevent capture locally and return a nil UUID since we
// cannot create an attachment envelope-item for the minidump file.
const sentry_uuid_t event_id
= sentry_capture_minidump("some_invalid_minidump_path");
TEST_CHECK(sentry_uuid_is_nil(&event_id));

sentry_close();
}
2 changes: 1 addition & 1 deletion tests/unit/test_os_release.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,4 @@ SENTRY_TEST(os_release_non_existent_files)
sentry_value_t os_release = get_linux_os_release("invalid_path");
TEST_ASSERT(sentry_value_is_null(os_release));
#endif // !defined(SENTRY_PLATFORM_LINUX) || defined(SENTRY_PLATFORM_ANDROID)
}
}
4 changes: 4 additions & 0 deletions tests/unit/tests.inc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ XX(basic_write_envelope_to_file)
XX(bgworker_flush)
XX(breadcrumb_without_type_or_message_still_valid)
XX(build_id_parser)
XX(capture_minidump_basic)
XX(capture_minidump_invalid_path)
XX(capture_minidump_null_path)
XX(capture_minidump_without_sentry_init)
XX(check_version)
XX(child_spans)
XX(child_spans_ts)
Expand Down

0 comments on commit 05b907e

Please sign in to comment.