sentry-cli icon indicating copy to clipboard operation
sentry-cli copied to clipboard

Sentry silently fails to load properties from a .env file.

Open cjshearer opened this issue 2 years ago • 1 comments

OS:

  • [ ] Windows
  • [x] MacOS
  • [ ] Linux

Platform:

  • [x] iOS
  • [x] Android

SDK:

  • [x] @sentry/react-native (>= 1.0.0)
  • [ ] react-native-sentry (<= 0.43.2)

@sentry/react-native version: 5.5.0 react-native version: 0.71.7

Are you using Expo?

  • [ ] Yes
  • [x] No

Are you using sentry.io or on-premise?

  • [x] sentry.io (SaaS)
  • [ ] on-premise

If you are using sentry.io, please post a link to your issue so we can take a look:

N/A

Configuration:

(@sentry/react-native) My issue pertains to the native iOS/Android build phase, so I doubt the JS configuration is relevant.


I have following issue:

When Sentry fails to load configuration values from a .env file, it does so silently, then noisily fails to load from a sentry.properties if not present. I spent several hours troubleshooting this and reading through the documentation that confirms that loading from a .env is supported before I decided to test a potential workaround that would involve loading the .env into the environment with source .env, which revealed that my .env file could not be loaded due to a value containing unquoted whitespace. Removing the unquoted whitespace solved the problem, allowing me to load the properties from the .env, but Sentry should have said something in the build logs about it trying and failing to load from .env.

Steps to reproduce:

  • Initialize Sentry with the Sentry wizard: npx @sentry/wizard -s -i reactNative
  • Remove the sentry.properties files in favor of providing the required values through an .env file placed at the root directory of your project. Also add a property with some whitespace:
SPOOKY_WHITESPACE=s p o o k y  w h i t e s p a c e
SENTRY_AUTH_TOKEN=...
SENTRY_DSN=...
SENTRY_ORG=...
SENTRY_PROJECT=...
SENTRY_URL=... 
  • Run a release build on Android or iOS.

Actual result:

...
Failed to find file referenced by SENTRY_PROPERTIES 
error: An organization slug is required (provide with --org)

Expected result:

Failed to load Sentry properties from `some/path/.env`: (perhaps some more details about the failure).
Falling back to `file/referenced/by/SENTRY_PROPERTIES`.
Failed to find file referenced by SENTRY_PROPERTIES .

cjshearer avatar May 22 '23 21:05 cjshearer

Hi, thanks for all the details. I'm sorry to hear this caused you trouble.

This is definitely something we can improve on the sentry-cli.

Related .env load code: https://github.com/getsentry/sentry-cli/blob/fdaaad1d841e140f942c8dd2a0561901f373a896/src/utils/system.rs#L178-L189

krystofwoldrich avatar May 23 '23 09:05 krystofwoldrich