Skip to content
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

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

Closed
6 of 11 tasks
cjshearer opened this issue May 22, 2023 · 1 comment · Fixed by #1987
Closed
6 of 11 tasks

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

cjshearer opened this issue May 22, 2023 · 1 comment · Fixed by #1987

Comments

@cjshearer
Copy link

cjshearer commented May 22, 2023

OS:

  • Windows
  • MacOS
  • Linux

Platform:

  • iOS
  • Android

SDK:

  • @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
  • No

Are you using sentry.io or on-premise?

  • 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 cjshearer changed the title Sentry _silently_ fails to load properties from a .env file. Sentry silently fails to load properties from a .env file. May 22, 2023
@krystofwoldrich
Copy link
Member

krystofwoldrich commented May 23, 2023

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:

pub fn load_dotenv() {
if env::var("SENTRY_LOAD_DOTENV")
.map(|x| x.as_str() == "1")
.unwrap_or(true)
{
if let Ok(path) = env::var("SENTRY_DOTENV_PATH") {
dotenv::from_path(path).ok();
} else {
dotenv::dotenv().ok();
}
}
}

@krystofwoldrich krystofwoldrich transferred this issue from getsentry/sentry-react-native May 23, 2023
@szokeasaurusrex szokeasaurusrex self-assigned this Mar 19, 2024
szokeasaurusrex added a commit that referenced this issue Mar 25, 2024
If there is an error loading a .env file, we now print a warning message. There is no warning when the .env was not found because users might not have set up a .env; we only warn when the .env was found but there was some error reading it.

Fixes GH-1624
@github-project-automation github-project-automation bot moved this from Needs Discussion to Done in Mobile & Cross Platform SDK Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants