Skip to content

Commit 9fa0a49

Browse files
antonisclaude
andauthored
fix(android): Report missing properties file or keys when flavorAware is enabled (#6031)
* fix(android): Report missing properties file or keys when flavorAware is enabled When `flavorAware` is set and the per-variant properties file is missing, or required keys (`auth.token`/`SENTRY_AUTH_TOKEN`, `defaults.org`, `defaults.project`) are absent, sentry.gradle previously swallowed the error and passed `null` values to sentry-cli, failing with an opaque `Illegal null value provided in this collection`. Validate the file and required keys up front and throw a `GradleException` naming the expected path and any missing keys. Also only append `--url` when `defaults.url` is set, so sentry-cli can fall back to its default. Fixes #2839 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * docs: Link changelog entry to PR instead of issue Matches convention used by other entries under Unreleased. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent bafca82 commit 9fa0a49

2 files changed

Lines changed: 35 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
### Fixes
2020

2121
- Check `captureReplay` return value in iOS bridge to avoid linking error events to uncaptured replays ([#6008](https://github.com/getsentry/sentry-react-native/pull/6008))
22+
- Report the expected properties file path and any missing keys when using `flavorAware` on Android, instead of failing with an opaque `Illegal null value provided in this collection` error ([#6031](https://github.com/getsentry/sentry-react-native/pull/6031))
2223

2324
### Dependencies
2425

packages/core/sentry.gradle

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,31 @@ plugins.withId('com.android.application') {
208208
try {
209209
sentryProps.load(new FileInputStream(propertiesFile))
210210
} catch (FileNotFoundException e) {
211+
if (config.flavorAware) {
212+
throw new GradleException(
213+
"Sentry: expected properties file not found for variant '${variant}': ${propertiesFile}. " +
214+
"Create it, or disable 'flavorAware' in project.ext.sentryCli.")
215+
}
211216
project.logger.info("file not found '$propertiesFile' for '$variant'")
212217
}
213218

219+
def sentryUrl = sentryProps.get("defaults.url")
220+
def sentryAuthToken = sentryProps.get("auth.token") ?: System.getenv("SENTRY_AUTH_TOKEN")
221+
def sentryOrg = sentryProps.get("defaults.org")
222+
def sentryProject = sentryProps.get("defaults.project")
223+
224+
if (config.flavorAware) {
225+
def missing = []
226+
if (!sentryAuthToken) missing << "auth.token (or SENTRY_AUTH_TOKEN env var)"
227+
if (!sentryOrg) missing << "defaults.org"
228+
if (!sentryProject) missing << "defaults.project"
229+
if (!missing.isEmpty()) {
230+
throw new GradleException(
231+
"Sentry: missing required properties in '${propertiesFile}' for variant '${variant}':\n" +
232+
" - " + missing.join("\n - "))
233+
}
234+
}
235+
214236
def cliPackage = resolveSentryCliPackagePath(reactRoot)
215237
def cliExecutable = sentryProps.get("cli.executable", "$cliPackage/bin/sentry-cli")
216238

@@ -228,18 +250,22 @@ plugins.withId('com.android.application') {
228250
args.addAll(!config.logLevel ? [] : [
229251
"--log-level", config.logLevel // control verbosity of the output
230252
])
231-
args.addAll(!config.flavorAware ? [] : [
232-
"--url", sentryProps.get("defaults.url"),
233-
"--auth-token", sentryProps.get("auth.token") ?: System.getenv("SENTRY_AUTH_TOKEN")
234-
])
253+
if (config.flavorAware) {
254+
if (sentryUrl) {
255+
args.addAll(["--url", sentryUrl])
256+
}
257+
args.addAll(["--auth-token", sentryAuthToken])
258+
}
235259
args.addAll(["react-native", "gradle",
236260
"--bundle", bundleOutput, // The path to a bundle that should be uploaded.
237261
"--sourcemap", sourcemapOutput // The path to a sourcemap that should be uploaded.
238262
])
239-
args.addAll(!config.flavorAware ? [] : [
240-
"--org", sentryProps.get("defaults.org"),
241-
"--project", sentryProps.get("defaults.project")
242-
])
263+
if (config.flavorAware) {
264+
args.addAll([
265+
"--org", sentryOrg,
266+
"--project", sentryProject
267+
])
268+
}
243269

244270
args.addAll(extraArgs)
245271

0 commit comments

Comments
 (0)