Merge pull request #4391 from fufesou/refact/remove_all_assert
remove assert
This commit is contained in:
commit
c872b52bd4
@ -279,7 +279,6 @@ fn request_plugin_sign(id: String, msg_to_rustdesk: MsgToRustDesk) -> PluginRetu
|
||||
"parse signature data '{}'",
|
||||
signature_data
|
||||
);
|
||||
// to-do: Request server to sign the data.
|
||||
thread::spawn(move || {
|
||||
let sign_url = format!("{}/lic/web/api/plugin-sign", get_api_server());
|
||||
let client = reqwest::blocking::Client::new();
|
||||
@ -311,7 +310,16 @@ fn request_plugin_sign(id: String, msg_to_rustdesk: MsgToRustDesk) -> PluginRetu
|
||||
&[],
|
||||
) {
|
||||
Ok(ret) => {
|
||||
assert!(!ret.msg.is_null());
|
||||
debug_assert!(!ret.msg.is_null(), "msg is null");
|
||||
if ret.msg.is_null() {
|
||||
// unreachable
|
||||
log::error!(
|
||||
"The returned message pointer of plugin status is null, plugin id: '{}', code: {}",
|
||||
id,
|
||||
ret.code,
|
||||
);
|
||||
return;
|
||||
}
|
||||
let msg = cstr_to_string(ret.msg).unwrap_or_default();
|
||||
free_c_ptr(ret.msg as _);
|
||||
if ret.code == super::errno::ERR_SUCCESS {
|
||||
|
@ -76,11 +76,18 @@ impl PluginReturn {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_code_msg(&mut self) -> (i32, String) {
|
||||
pub fn get_code_msg(&mut self, id: &str) -> (i32, String) {
|
||||
if self.is_success() {
|
||||
(self.code, "".to_owned())
|
||||
} else {
|
||||
debug_assert!(!self.msg.is_null(), "msg is null");
|
||||
if self.msg.is_null() {
|
||||
log::warn!(
|
||||
"The message pointer from the plugin '{}' is null, but the error code is {}",
|
||||
id,
|
||||
self.code
|
||||
);
|
||||
return (self.code, "".to_owned());
|
||||
}
|
||||
let msg = cstr_to_string(self.msg).unwrap_or_default();
|
||||
free_c_ptr(self.msg as _);
|
||||
self.msg = null();
|
||||
@ -146,7 +153,6 @@ fn get_uninstall_file_path() -> ResultType<PathBuf> {
|
||||
|
||||
#[inline]
|
||||
fn cstr_to_string(cstr: *const c_char) -> ResultType<String> {
|
||||
assert!(!cstr.is_null(), "cstr must be a valid pointer");
|
||||
if cstr.is_null() {
|
||||
bail!("failed to convert string, the pointer is null");
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ macro_rules! make_plugin {
|
||||
fn init(&self, data: &InitData, path: &str) -> ResultType<()> {
|
||||
let mut init_ret = (self.init)(data as _);
|
||||
if !init_ret.is_success() {
|
||||
let (code, msg) = init_ret.get_code_msg();
|
||||
let (code, msg) = init_ret.get_code_msg(path);
|
||||
bail!(
|
||||
"Failed to init plugin {}, code: {}, msg: {}",
|
||||
path,
|
||||
@ -227,7 +227,7 @@ macro_rules! make_plugin {
|
||||
fn clear(&self, id: &str) {
|
||||
let mut clear_ret = (self.clear)();
|
||||
if !clear_ret.is_success() {
|
||||
let (code, msg) = clear_ret.get_code_msg();
|
||||
let (code, msg) = clear_ret.get_code_msg(id);
|
||||
log::error!(
|
||||
"Failed to clear plugin {}, code: {}, msg: {}",
|
||||
id,
|
||||
@ -428,7 +428,7 @@ pub fn plugin_call(id: &str, method: &[u8], peer: &str, event: &[u8]) -> ResultT
|
||||
if ret.is_success() {
|
||||
Ok(())
|
||||
} else {
|
||||
let (code, msg) = ret.get_code_msg();
|
||||
let (code, msg) = ret.get_code_msg(id);
|
||||
bail!(
|
||||
"Failed to handle plugin event, id: {}, method: {}, code: {}, msg: {}",
|
||||
id,
|
||||
@ -496,7 +496,7 @@ fn _handle_listen_event(event: String, peer: String) {
|
||||
evt_bytes.len(),
|
||||
);
|
||||
if !ret.is_success() {
|
||||
let (code, msg) = ret.get_code_msg();
|
||||
let (code, msg) = ret.get_code_msg(&id);
|
||||
log::error!(
|
||||
"Failed to handle plugin listen event, id: {}, event: {}, code: {}, msg: {}",
|
||||
id,
|
||||
@ -540,7 +540,7 @@ pub fn handle_client_event(id: &str, peer: &str, event: &[u8]) -> Message {
|
||||
free_c_ptr(out as _);
|
||||
msg
|
||||
} else {
|
||||
let (code, msg) = ret.get_code_msg();
|
||||
let (code, msg) = ret.get_code_msg(id);
|
||||
if code > ERR_RUSTDESK_HANDLE_BASE && code < ERR_PLUGIN_HANDLE_BASE {
|
||||
log::debug!(
|
||||
"Plugin {} failed to handle client event, code: {}, msg: {}",
|
||||
|
Loading…
x
Reference in New Issue
Block a user