From 9b627240f2ebe7c175813025c6c1e2f65806f4db Mon Sep 17 00:00:00 2001 From: M Mahrous Date: Tue, 30 Sep 2025 15:07:53 +0200 Subject: [PATCH] [FIX] do not panic on creating custom entry on ns --- server/src/constants.rs | 14 ++++++++++++++ server/src/core/entry_point.rs | 8 +++++--- server/src/utils.rs | 11 +++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/server/src/constants.rs b/server/src/constants.rs index fabebb9b..31850ba4 100644 --- a/server/src/constants.rs +++ b/server/src/constants.rs @@ -124,3 +124,17 @@ pub const BUILT_IN_LIBS: &[&str] = &["string", "re", "difflib", "textwrap", "un "pipes", "smtpd", "sndhdr", "spwd", "sunau", "telnetlib", "uu", "xdrlib", "struct", "codecs"]; pub const CONFIG_WIKI_URL: &str = "https://github.com/odoo/odoo-ls/wiki/Configuration-files"; + +use std::sync::LazyLock; + +/// True if the minor part of EXTENSION_VERSION is even, false otherwise. +pub static IS_RELEASE: LazyLock = LazyLock::new(|| { + let parts: Vec<&str> = EXTENSION_VERSION.split('.').collect(); + if parts.len() < 2 { + return false; + } + if let Ok(minor) = parts[1].parse::() { + return minor % 2 == 0; + } + false +}); diff --git a/server/src/core/entry_point.rs b/server/src/core/entry_point.rs index 2c1b064f..f5c0f866 100644 --- a/server/src/core/entry_point.rs +++ b/server/src/core/entry_point.rs @@ -3,7 +3,7 @@ use std::{cell::RefCell, cmp, collections::HashMap, path::PathBuf, rc::{Rc, Weak use tracing::{error, info, warn}; use weak_table::PtrWeakHashSet; -use crate::{constants::{flatten_tree, BuildSteps, OYarn, PackageType, SymType, Tree}, threads::SessionInfo, utils::PathSanitizer}; +use crate::{constants::{flatten_tree, BuildSteps, OYarn, PackageType, SymType, Tree}, threads::SessionInfo, utils::PathSanitizer, warn_or_panic}; use super::{odoo::SyncOdoo, symbols::symbol::Symbol}; @@ -179,10 +179,12 @@ impl EntryPointMgr { if file_path.ends_with("__manifest__.py") { warn!("new custom entry point for manifest without related init.py is not supported outside of main entry point. skipping..."); session.sync_odoo.entry_point_mgr.borrow_mut().remove_entries_with_path(tree_path); - return false; } else { - panic!("Trying to create a custom entrypoint on a namespace symbol: {:?}", new_sym.borrow().paths()); + // There was an __init__.py, that was renamed or deleted. + // Another notification will come for the deletion of the file, so we just warn here. + warn_or_panic!("Trying to create a custom entrypoint on a namespace symbol: {:?}", new_sym.borrow().paths()); } + return false; } _ => {panic!("Unexpected symbol type: {:?}", new_sym_typ);} } diff --git a/server/src/utils.rs b/server/src/utils.rs index 048cf25b..85902788 100644 --- a/server/src/utils.rs +++ b/server/src/utils.rs @@ -334,3 +334,14 @@ pub fn is_python_path(path: &String) -> bool { } } +#[macro_export] +macro_rules! warn_or_panic { + ($($arg:tt)*) => { + if *crate::constants::IS_RELEASE { + let bt = std::backtrace::Backtrace::force_capture(); + tracing::warn!("{}\nBacktrace:\n{:?}", format!($($arg)*), bt); + } else { + panic!($($arg)*); + } + } +}