Skip to content

Commit 9e2af61

Browse files
mmahroussfda-odoo
authored andcommitted
[FIX] do not panic on creating custom entry on ns
1 parent d3de1e0 commit 9e2af61

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

server/src/constants.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,17 @@ pub const BUILT_IN_LIBS: &[&str] = &["string", "re", "difflib", "textwrap", "un
124124
"pipes", "smtpd", "sndhdr", "spwd", "sunau", "telnetlib", "uu", "xdrlib", "struct", "codecs"];
125125

126126
pub const CONFIG_WIKI_URL: &str = "https://github.com/odoo/odoo-ls/wiki/Configuration-files";
127+
128+
use std::sync::LazyLock;
129+
130+
/// True if the minor part of EXTENSION_VERSION is even, false otherwise.
131+
pub static IS_RELEASE: LazyLock<bool> = LazyLock::new(|| {
132+
let parts: Vec<&str> = EXTENSION_VERSION.split('.').collect();
133+
if parts.len() < 2 {
134+
return false;
135+
}
136+
if let Ok(minor) = parts[1].parse::<u32>() {
137+
return minor % 2 == 0;
138+
}
139+
false
140+
});

server/src/core/entry_point.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{cell::RefCell, cmp, collections::HashMap, path::PathBuf, rc::{Rc, Weak
33
use tracing::{error, info, warn};
44
use weak_table::PtrWeakHashSet;
55

6-
use crate::{constants::{flatten_tree, BuildSteps, OYarn, PackageType, SymType, Tree}, threads::SessionInfo, utils::PathSanitizer};
6+
use crate::{constants::{flatten_tree, BuildSteps, OYarn, PackageType, SymType, Tree}, threads::SessionInfo, utils::PathSanitizer, warn_or_panic};
77

88
use super::{odoo::SyncOdoo, symbols::symbol::Symbol};
99

@@ -179,10 +179,12 @@ impl EntryPointMgr {
179179
if file_path.ends_with("__manifest__.py") {
180180
warn!("new custom entry point for manifest without related init.py is not supported outside of main entry point. skipping...");
181181
session.sync_odoo.entry_point_mgr.borrow_mut().remove_entries_with_path(tree_path);
182-
return false;
183182
} else {
184-
panic!("Trying to create a custom entrypoint on a namespace symbol: {:?}", new_sym.borrow().paths());
183+
// There was an __init__.py, that was renamed or deleted.
184+
// Another notification will come for the deletion of the file, so we just warn here.
185+
warn_or_panic!("Trying to create a custom entrypoint on a namespace symbol: {:?}", new_sym.borrow().paths());
185186
}
187+
return false;
186188
}
187189
_ => {panic!("Unexpected symbol type: {:?}", new_sym_typ);}
188190
}

server/src/utils.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,14 @@ pub fn is_python_path(path: &String) -> bool {
334334
}
335335
}
336336

337+
#[macro_export]
338+
macro_rules! warn_or_panic {
339+
($($arg:tt)*) => {
340+
if *crate::constants::IS_RELEASE {
341+
let bt = std::backtrace::Backtrace::force_capture();
342+
tracing::warn!("{}\nBacktrace:\n{:?}", format!($($arg)*), bt);
343+
} else {
344+
panic!($($arg)*);
345+
}
346+
}
347+
}

0 commit comments

Comments
 (0)