Skip to content

Commit 2353fa1

Browse files
authored
fix: Print better error messages for org auth tokens (#1756)
1 parent 8458529 commit 2353fa1

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/config.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ impl TokenData {
6060
.decode(encoded.as_bytes())
6161
.context("invalid base64 data")?;
6262

63-
Ok(serde_json::from_slice(&json)?)
63+
let json =
64+
serde_json::from_slice::<serde_json::Value>(&json).context("Failed to decode JSON")?;
65+
66+
if matches!(json.get("url"), Some(serde_json::Value::Null) | None) {
67+
bail!("Org auth token is missing a URL. Please make sure that `system.url-prefix` is set in your Sentry config.yml.");
68+
}
69+
70+
serde_json::from_value(json).context("Failed to decode org auth token")
6471
}
6572
}
6673

@@ -92,9 +99,8 @@ impl Config {
9299
pub fn from_file(filename: PathBuf, ini: Ini) -> Result<Config> {
93100
let auth = get_default_auth(&ini);
94101
let token_embedded_data = match auth {
95-
Some(Auth::Token(ref token)) => {
96-
TokenData::decode(token).context("Failed to parse org auth token {token}")?
97-
}
102+
Some(Auth::Token(ref token)) => TokenData::decode(token)
103+
.context(format!("Failed to parse org auth token {token}"))?,
98104
_ => None,
99105
};
100106

@@ -207,8 +213,8 @@ impl Config {
207213
self.ini.delete_from(Some("auth"), "token");
208214
match self.cached_auth {
209215
Some(Auth::Token(ref val)) => {
210-
self.cached_token_data =
211-
TokenData::decode(val).context("Failed to parse org auth token {token}")?;
216+
self.cached_token_data = TokenData::decode(val)
217+
.context(format!("Failed to parse org auth token {val}"))?;
212218

213219
if let Some(ref data) = self.cached_token_data {
214220
self.cached_base_url = data.url.clone();

0 commit comments

Comments
 (0)