Skip to content

Commit 42e456e

Browse files
fix: Only warn about mismatched URLs when they are different (#2143)
Previously, we warned about a mismatch between the auth token URL and the manually configured URL even when they were the same. We also sometimes issued the warning when no URL was manually configured (i.e. when the default https://sentry.io/ was used). Now, we only warn when the two are actually different and we also only warn if a URL was actually manually configured. Fixes #2137
1 parent b790f2d commit 42e456e

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/config.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,16 @@ impl Config {
6565
_ => None, // get_default_auth never returns Auth::Token variant
6666
};
6767

68-
let default_url = get_default_url(&ini);
68+
let manually_configured_url = configured_url(&ini);
6969
let token_url = token_embedded_data
7070
.as_ref()
7171
.map(|td| td.url.as_str())
7272
.unwrap_or_default();
7373

7474
let url = if token_url.is_empty() {
75-
default_url
75+
manually_configured_url.unwrap_or_else(|| DEFAULT_URL.to_string())
7676
} else {
77-
if !default_url.is_empty() {
78-
log::warn!(
79-
"Using {token_url} (embedded in token) rather than manually-configured URL {default_url}. \
80-
To use {default_url}, please provide an auth token for this URL."
81-
);
82-
}
77+
warn_about_conflicting_urls(token_url, manually_configured_url.as_deref());
8378
token_url.into()
8479
};
8580

@@ -535,6 +530,18 @@ impl Config {
535530
}
536531
}
537532

533+
fn warn_about_conflicting_urls(token_url: &str, manually_configured_url: Option<&str>) {
534+
if let Some(manually_configured_url) = manually_configured_url {
535+
if manually_configured_url != token_url {
536+
warn!(
537+
"Using {token_url} (embedded in token) rather than manually-configured URL \
538+
{manually_configured_url}. To use {manually_configured_url}, please provide an \
539+
auth token for {manually_configured_url}."
540+
);
541+
}
542+
}
543+
}
544+
538545
fn find_global_config_file() -> Result<PathBuf> {
539546
let home_dir_file = dirs::home_dir().map(|p| p.join(CONFIG_RC_FILE_NAME));
540547
let config_dir_file = dirs::config_dir().map(|p| p.join(CONFIG_INI_FILE_PATH));
@@ -694,14 +701,13 @@ fn get_default_auth(ini: &Ini) -> Option<Auth> {
694701
}
695702
}
696703

697-
fn get_default_url(ini: &Ini) -> String {
698-
if let Ok(val) = env::var("SENTRY_URL") {
699-
val
700-
} else if let Some(val) = ini.get_from(Some("defaults"), "url") {
701-
val.to_owned()
702-
} else {
703-
DEFAULT_URL.to_owned()
704-
}
704+
/// Returns the URL configured in the SENTRY_URL environment variable or provided ini (in that
705+
/// order of precedence), or returns None if neither is set.
706+
fn configured_url(ini: &Ini) -> Option<String> {
707+
env::var("SENTRY_URL").ok().or_else(|| {
708+
ini.get_from(Some("defaults"), "url")
709+
.map(|url| url.to_owned())
710+
})
705711
}
706712

707713
fn get_default_headers(ini: &Ini) -> Option<Vec<String>> {

0 commit comments

Comments
 (0)