Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile error for async stateful commands that don't return a Result #2533

Open
probablykasper opened this issue Aug 25, 2021 · 3 comments
Open
Labels
scope: core Core packages of Tauri type: bug

Comments

@probablykasper
Copy link
Member

Describe the bug

Stateful async commands that don't return a Result give a compiler error.

To Reproduce

Example:

#[command]
pub async fn get_info(app: State<'_, Data>) -> bool {
  true
}

There's no error if you remove async, remove the app argument, or change the return type to a Result works.

Platform and Versions

Details
Operating System - Mac OS, version 10.15.7 X64

Node.js environment
  Node.js - 14.16.0
  @tauri-apps/cli - 1.0.0-beta.10
  @tauri-apps/api - 1.0.0-beta.8

Global packages
  npm - 6.14.11
  yarn - 1.22.10

Rust environment
  rustc - 1.54.0
  cargo - 1.54.0

App directory structure
/node_modules
/src-tauri
/build
/.git
/src

App
  tauri.rs - 1.0.0-beta.8
  build-type - bundle
  CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'
  distDir - ../build
  devPath - http://localhost:8000
  framework - Svelte

Stack Trace

error[E0597]: `__tauri_message__` does not live long enough
  --> src/cmd.rs:93:1
   |
93 |   #[command]
   |   ^^^^^^^^^-
   |   |        |
   |   |        `__tauri_message__` dropped here while still borrowed
   |   borrowed value does not live long enough
   |   argument requires that `__tauri_message__` is borrowed for `'static`
@zsmatrix62

This comment has been minimized.

@amrbashir amrbashir added the scope: core Core packages of Tauri label Dec 21, 2021
valerauko added a commit to valerauko/gitegylet that referenced this issue Jul 22, 2022
@ricardomatias
Copy link

Is there any interim solution?

@FabianLars
Copy link
Sponsor Member

For now you just have to return a Result. If you don't want to return anything from the command it can be as simple as Result<(), ()> or in case of the OP's example it'd be Result<bool, ()>.

This doesn't change what you'll receive on the JavaScript side. Ok will resolve the Promise and Err will reject it.

Pascal-So added a commit to Pascal-So/tauri that referenced this issue Jan 22, 2023
Async commands currently have to return `Result`
due to the way they are mapped to JS promises.
Once issue tauri-apps#2533 is resolved, this commit can be
reverted.
Pascal-So added a commit to Pascal-So/tauri that referenced this issue Jan 22, 2023
Async commands that contain references in their
arguments currently have to return `Result`.
Once issue tauri-apps#2533 is resolved, this commit can be
reverted.
Pascal-So added a commit to Pascal-So/tauri that referenced this issue Apr 18, 2023
Async commands that contain references in their
arguments currently have to return `Result`.
Once issue tauri-apps#2533 is resolved, this commit can be
reverted.
Pascal-So added a commit to Pascal-So/tauri that referenced this issue Apr 18, 2023
Async commands that contain references in their
arguments currently have to return `Result`.
Once issue tauri-apps#2533 is resolved, this commit can be
reverted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: core Core packages of Tauri type: bug
Projects
Status: 📬Proposal
Development

No branches or pull requests

5 participants