Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(cli): clarify symbol upload finalize failures (#61299)

Catalin Irimie11bf03f2cf1c
diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md
index ee15be32de21..713f632c619c 100644
--- a/cli/CHANGELOG.md
+++ b/cli/CHANGELOG.md
@@ -1,5 +1,9 @@
# posthog-cli
+# 0.7.15
+
+- fix: make symbol upload retry logs clearer and report failed finalization explicitly.
+
# 0.7.14
- feat: add `--env-file <PATH>` to load `POSTHOG_CLI_HOST`, `POSTHOG_CLI_API_KEY`, and `POSTHOG_CLI_PROJECT_ID` (and their legacy aliases) from a dotenv-style file when not set in the process environment. Credentials are resolved atomically from a single source (process env first, then the file), so `POSTHOG_CLI_HOST` from the file cannot redirect a key supplied by the process env.
diff --git a/cli/Cargo.lock b/cli/Cargo.lock
index 2dcd79f4ad10..6fb19c1af1da 100644
--- a/cli/Cargo.lock
+++ b/cli/Cargo.lock
@@ -1851,7 +1851,7 @@ dependencies = [
[[package]]
name = "posthog-cli"
-version = "0.7.14"
+version = "0.7.15"
dependencies = [
"anyhow",
"chrono",
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index e3e70881d088..b72789a94575 100644
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "posthog-cli"
-version = "0.7.14"
+version = "0.7.15"
authors = [
"David <[email protected]>",
diff --git a/cli/src/api/symbol_sets.rs b/cli/src/api/symbol_sets.rs
index 31b033096869..7d467d4b4a3f 100644
--- a/cli/src/api/symbol_sets.rs
+++ b/cli/src/api/symbol_sets.rs
@@ -12,6 +12,8 @@ use crate::{
};
const MAX_FILE_SIZE: usize = 100 * 1024 * 1024; // 100 MB
+const FINISH_UPLOAD_ERROR_MESSAGE: &str =
+ "Failed to finalize symbol upload; maps were not attached";
#[derive(Error, Debug)]
pub enum UploadError {
@@ -219,7 +221,7 @@ fn finish_upload(content_hashes: HashMap<String, String>) -> Result<(), UploadEr
|req| req.json(&request),
)
})
- .map_err(|e| UploadError::Other(anyhow::anyhow!(e).context("Failed to finish upload")))?;
+ .map_err(|e| UploadError::Other(anyhow::anyhow!(e).context(FINISH_UPLOAD_ERROR_MESSAGE)))?;
Ok(())
}
@@ -347,17 +349,128 @@ where
{
let mut attempt = 0;
let mut last_error: Option<E> = None;
- for delay in iterable {
+ let mut delays = iterable.peekable();
+ while let Some(delay) = delays.next() {
match func(attempt) {
Ok(res) => return Ok(res),
Err(e) => {
last_error = Some(e);
attempt += 1;
warn!("Operation failed: {last_error:?}");
- warn!("Retrying in {delay:?}, attempt {attempt}");
- sleep(delay);
+ if delays.peek().is_some() {
+ warn!("Retrying in {delay:?}, attempt {attempt}");
+ sleep(delay);
+ }
}
}
}
Err(last_error.expect("retry called with empty iterator - max_attempts must be > 0"))
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use std::{
+ fmt::Debug,
+ sync::{Arc, Mutex},
+ };
+ use tracing::{field::Visit, Event, Subscriber};
+ use tracing_subscriber::{layer::Context, prelude::*, registry::Registry, Layer};
+
+ #[derive(Default)]
+ struct MessageVisitor {
+ message: Option<String>,
+ }
+
+ impl Visit for MessageVisitor {
+ fn record_debug(&mut self, field: &tracing::field::Field, value: &dyn Debug) {
+ if field.name() == "message" {
+ self.message = Some(format!("{value:?}"));
+ }
+ }
+
+ fn record_str(&mut self, field: &tracing::field::Field, value: &str) {
+ if field.name() == "message" {
+ self.message = Some(value.to_string());
+ }
+ }
+ }
+
+ #[derive(Clone)]
+ struct RecordingLayer {
+ messages: Arc<Mutex<Vec<String>>>,
+ }
+
+ impl<S: Subscriber> Layer<S> for RecordingLayer {
+ fn on_event(&self, event: &Event<'_>, _ctx: Context<'_, S>) {
+ let mut visitor = MessageVisitor::default();
+ event.record(&mut visitor);
+ if let Some(message) = visitor.message {
+ self.messages.lock().unwrap().push(message);
+ }
+ }
+ }
+
+ fn capture_tracing_messages<F: FnOnce()>(f: F) -> Vec<String> {
+ let messages = Arc::new(Mutex::new(Vec::new()));
+ let subscriber = Registry::default().with(RecordingLayer {
+ messages: messages.clone(),
+ });
+
+ tracing::subscriber::with_default(subscriber, f);
+
+ let captured = messages.lock().unwrap().clone();
+ captured
+ }
+
+ #[test]
+ fn retry_does_not_log_retry_after_final_attempt() {
+ let messages = capture_tracing_messages(|| {
+ let result: Result<(), &str> = retry(
+ vec![Duration::ZERO, Duration::ZERO, Duration::ZERO].into_iter(),
+ |_| Err("still broken"),
+ );
+
+ assert_eq!(result.unwrap_err(), "still broken");
+ });
+
+ let retry_logs = messages
+ .iter()
+ .filter(|message| message.contains("Retrying in"))
+ .count();
+
+ assert_eq!(retry_logs, 2);
+ }
+
+ #[test]
+ fn finish_upload_failure_message_names_unattached_maps() {
+ crate::invocation_context::INVOCATION_CONTEXT.get_or_init(|| {
+ let config = crate::invocation_context::InvocationConfig {
+ api_key: "phx_test".to_string(),
+ host: "not a valid url".to_string(),
+ env_id: "1".to_string(),
+ skip_ssl: false,
+ rate_limit: 1000,
+ };
+ let client = crate::api::client::PHClient::from_config(config.clone()).unwrap();
+ crate::invocation_context::InvocationContext::new(config, client)
+ });
+
+ let err = finish_upload(HashMap::from([(
+ "symbol-set-id".to_string(),
+ "content-hash".to_string(),
+ )]))
+ .unwrap_err();
+ let UploadError::Other(err) = err else {
+ panic!("expected UploadError::Other");
+ };
+
+ let chain = err.chain().map(ToString::to_string).collect::<Vec<_>>();
+ assert!(
+ chain.iter().any(
+ |message| message == "Failed to finalize symbol upload; maps were not attached"
+ ),
+ "finish_upload error chain should explain that maps were not attached, got {chain:?}"
+ );
+ }
+}