I use Tauri to build a GUI.
In my backend, I define two functions that will be invoked in the frontend:
#[tauri::command]
fn functional_test(msg: String){
println!("Received : {}", msg);
}
#[tauri::command]
fn no_functional_test(my_msg: String){
println!("Received : {}", my_msg)
}
Note that the difference between the two functions is the parameter’s name: msg or my_msg
Basically, I have this part of code to init tauri:
fn main() {
tauri::Builder::default()
.setup(...)
.invoke_handler(tauri::generate_handler![functional_test, no_functional_test])
.run(tauri::generate_context!())
.expect("failed to run app");
}
In the frontend (using react), I have among all this block of code:
export function AComponent({name}: {name: string}){
useEffect(() => {
const fetchSomething = async () => {
try {
await invoke('functional_test', {msg:"This is a message"})
await invoke('no_functional_test', {my_msg:"This is also a message"})
} catch (error) {
await invoke('functional_test', {msg:error})
}
};
fetchSomething();
}, [name]);
return (...)
}
What’s happening here: I try to invoke each one of the two functions.
Because I don’t know how to display logs of the frontend, I use the functional function to debug.
There is the output:
Received : This is a message
Received : invalid args `myMsg` for command `no_functional_test`: command no_functional_test missing required key myMsg
Obviously, the first line of the result is the execution of the 6th line of the frontend code, but the second line is the execution of the 10th line, because the 7th line causes an error.
As we see, tauri expects the parameter to have the name myMsg, and not my_msg as I defined it in the back.
So here are my questions: What’s happening ? Is this normal ? Is there any documentation or other threads dealing with this problem and especially the causes ?