From bfba8cc035dfd24b5aa7585cec2eba6e0bac3770 Mon Sep 17 00:00:00 2001 From: Deepak Kumar Date: Sun, 29 Mar 2026 21:19:13 -0700 Subject: [PATCH 1/2] Make soft_error! return Ok in OSS builds and remove .unwrap() at call sites --- app/buck2_env/src/soft_error.rs | 8 -------- .../src/sqlite/incremental_state_db.rs | 10 ++++------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/app/buck2_env/src/soft_error.rs b/app/buck2_env/src/soft_error.rs index d929bfa201e08..a9966ee5aea2e 100644 --- a/app/buck2_env/src/soft_error.rs +++ b/app/buck2_env/src/soft_error.rs @@ -291,14 +291,6 @@ pub fn handle_soft_error( return Err(err.context("Upgraded warning to failure via $BUCK2_HARD_ERROR")); } - // @oss-disable: let is_open_source = false; - let is_open_source = true; // @oss-enable - if is_open_source { - // We don't log these, and we have no legacy users, and they might not upgrade that often, - // so lets just break open source things immediately. - return Err(err); - } - Ok(err) } diff --git a/app/buck2_execute_impl/src/sqlite/incremental_state_db.rs b/app/buck2_execute_impl/src/sqlite/incremental_state_db.rs index 4d669510b6b6d..23741deb414f3 100644 --- a/app/buck2_execute_impl/src/sqlite/incremental_state_db.rs +++ b/app/buck2_execute_impl/src/sqlite/incremental_state_db.rs @@ -71,7 +71,7 @@ impl IncrementalDbState { self.state.insert(key.to_owned(), value.clone().into()); if let Err(e) = db.incremental_state_table().insert(key.to_owned(), value) { - soft_error!( + let _unused = soft_error!( "insert_to_incremental_db", buck2_error::buck2_error!( buck2_error::ErrorTag::Tier0, @@ -79,8 +79,7 @@ impl IncrementalDbState { key, e ), quiet: true - ) - .unwrap(); + ); }; } None => { @@ -95,7 +94,7 @@ impl IncrementalDbState { { // This should be converted into a real error later, marking as a soft error for now as the row not existing // might show up as an error but doesn't actually matter in reality. - soft_error!( + let _unused = soft_error!( "delete_from_incremental_db", buck2_error::buck2_error!( buck2_error::ErrorTag::Tier0, @@ -103,8 +102,7 @@ impl IncrementalDbState { e ), quiet: true - ) - .unwrap(); + ); } self.state.remove(key); From 0a5ca111f6cc541a239d594c58aea6dc5c4f408e Mon Sep 17 00:00:00 2001 From: Deepak Kumar Date: Thu, 16 Apr 2026 16:14:10 -0700 Subject: [PATCH 2/2] Parameterize soft_error! OSS behavior based on deprecation flag Only treat deprecation soft errors as hard errors in OSS builds. Non-deprecation soft errors (used for logging) now return Ok in OSS, matching FB internal behavior and preventing panics at .unwrap() sites. Made-with: Cursor --- app/buck2_env/src/soft_error.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/buck2_env/src/soft_error.rs b/app/buck2_env/src/soft_error.rs index a9966ee5aea2e..07158d9538acc 100644 --- a/app/buck2_env/src/soft_error.rs +++ b/app/buck2_env/src/soft_error.rs @@ -274,6 +274,8 @@ pub fn handle_soft_error( options.quiet = false; } + let is_deprecation = options.deprecation; + // We want to limit each error to appearing at most 10 times in a build (no point spamming people) if count.fetch_add(1, Ordering::SeqCst) < 10 { if let Some(handler) = HANDLER.get() { @@ -291,6 +293,14 @@ pub fn handle_soft_error( return Err(err.context("Upgraded warning to failure via $BUCK2_HARD_ERROR")); } + // @oss-disable: let is_open_source = false; + let is_open_source = true; // @oss-enable + if is_open_source && is_deprecation { + // Deprecation warnings should be hard errors in OSS since there are + // no legacy users that need the grace period. + return Err(err); + } + Ok(err) }