Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

**Breaking Changes**:

- Android NDK: `SentryNdk.init(NdkOptions)` now throws an `Exception` if init fails (non-zero return code) rather than silently swallowing the error. ([#1430](https://github.com/getsentry/sentry-native/pull/1430))

**Fixes**:

- Removed the 10-item limit per envelope for non-session data. Sessions are now limited to 100 per envelope, while other items (e.g., attachments) have no limit in amount. ([#1347](https://github.com/getsentry/sentry-native/pull/1347))
Expand Down
24 changes: 24 additions & 0 deletions ndk/lib/src/androidTest/java/io/sentry/ndk/SentryNdkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,30 @@ public void shutdownDoesNotFail() throws IOException {
// it does not crash
}

@Test(expected = IllegalStateException.class)
public void initThrowsException() throws IOException {
final TemporaryFolder temporaryFolder = TemporaryFolder.builder().build();
temporaryFolder.create();
final File outboxPath = temporaryFolder.newFolder("outboxPath");

//noinspection DataFlowIssue
final NdkOptions options =
new NdkOptions(
null,
true,
outboxPath.getAbsolutePath(),
"1.0.0",
"production",
"dist",
100,
"io.sentry.ndk");

// when initialized with a NULL dsn
SentryNdk.init(options);

// then it does crash
}

@Test
public void messageCaught() throws IOException {
final TemporaryFolder temporaryFolder = TemporaryFolder.builder().build();
Expand Down
17 changes: 15 additions & 2 deletions ndk/lib/src/main/java/io/sentry/ndk/SentryNdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,31 @@ public final class SentryNdk {

private SentryNdk() {}

private static native void initSentryNative(@NotNull final NdkOptions options);
/**
* Initializes sentry-native and returns 0 on success, non-zero on failure.
*
* @return -1 if an JNI or options configuration issue occurred, 1 if sentry native itself failed
* to initialize
*/
private static native int initSentryNative(@NotNull final NdkOptions options);

private static native void shutdown();

/**
* Init the NDK integration
*
* @param options the SentryAndroidOptions
* @throws IllegalStateException if sentry-native couldn't be initialized
*/
public static void init(@NotNull final NdkOptions options) {
loadNativeLibraries();
initSentryNative(options);
final int returnCode = initSentryNative(options);
if (returnCode > 0) {
throw new IllegalStateException(
"A sentry-native internal init error occurred, please check the logs for more details.");
} else if (returnCode < 0) {
throw new IllegalStateException("A sentry-native setup failure occurred");
}
}

/** Closes the NDK integration */
Expand Down
7 changes: 4 additions & 3 deletions ndk/lib/src/main/jni/sentry.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ static void send_envelope(sentry_envelope_t *envelope, void *data) {
sentry_envelope_free(envelope);
}

JNIEXPORT void JNICALL
JNIEXPORT jint JNICALL
Java_io_sentry_ndk_SentryNdk_initSentryNative(
JNIEnv *env,
jclass cls,
Expand Down Expand Up @@ -355,8 +355,8 @@ Java_io_sentry_ndk_SentryNdk_initSentryNative(
jfloat traces_sample_rate = (jfloat) (*env)->CallFloatMethod(env, sentry_ndk_options, traces_sample_rate_mid);
sentry_options_set_traces_sample_rate(options, traces_sample_rate);

sentry_init(options);
return;
int rv = sentry_init(options);
return (jint) rv;

fail:
if (!transport_owns_path) {
Expand All @@ -366,6 +366,7 @@ Java_io_sentry_ndk_SentryNdk_initSentryNative(
sentry_transport_free(transport);
}
sentry_options_free(options);
return (jint) -1;
}

JNIEXPORT void JNICALL
Expand Down
Loading