How to resolve the error [the method blocking_kind
exists for reference &Result<Article, rusqlite::Error>
, but its trait bounds were not satisfied]?
#3913
-
Help!!! 😭 use crate::state::AppState;
use anyhow::Result;
use rusqlite::params;
use serde::{Deserialize, Serialize};
use tauri::{command, State};
#[derive(Debug, Serialize, Deserialize)]
pub struct Article {
id: String,
content: String,
}
#[command] // error happens here
pub fn db_get_article(state: State<AppState>, id: &str) -> Result<Article> {
let db = &(*state).db;
let result: Article = db.conn.query_row(
"SELECT id,content from article WHERE id=?1",
params![id],
|row| Ok(Article { id: row.get(0)?, content: row.get(1)? }),
)?;
Ok(result)
} # error description
error[E0599]: the method `blocking_kind` exists for reference `&Result<Article, anyhow::Error>`, but its trait bounds were not satisfied
--> src/db/article.rs:13:1
|
13 | #[command]
| ^^^^^^^^^^ method cannot be called on `&Result<Article, anyhow::Error>` due to unsatisfied trait bounds
|
::: /Users/mps/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs:503:1
|
503 | pub enum Result<T, E> {
| ---------------------
| |
| doesn't satisfy `Result<Article, anyhow::Error>: Serialize`
| doesn't satisfy `_: tauri::command::private::ResultKind`
|
::: /Users/mps/.cargo/registry/src/github.com-1ecc6299db9ec823/anyhow-1.0.55/src/lib.rs:370:1
|
370 | pub struct Error {
| ---------------- doesn't satisfy `anyhow::Error: Into<InvokeError>`
|
::: src/db/mod.rs:32:3
|
32 | tauri::generate_handler![article::db_get_article, article::db_add_article]
| -------------------------------------------------------------------------- in this macro invocation
|
= note: the following trait bounds were not satisfied:
`anyhow::Error: Into<InvokeError>`
which is required by `Result<Article, anyhow::Error>: tauri::command::private::ResultKind`
`Result<Article, anyhow::Error>: Serialize`
which is required by `&Result<Article, anyhow::Error>: tauri::command::private::SerializeKind`
= note: this error originates in the macro `article::__cmd__db_get_article` (in Nightly builds, run with -Z macro-backtrace for more info) |
Beta Was this translation helpful? Give feedback.
Answered by
FabianLars
Apr 18, 2022
Replies: 1 comment 3 replies
-
Everything you return from commands must implement |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
percy507
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Everything you return from commands must implement
Serialize
, this includes Errors and anyhow's error type doesn't implement it.You basically have 2 choices here, either you convert errors to Strings or implement your own custom Error which implements Serialize and has
From
implementations for external errors. Here's the relevant section in our wip docs: https://jonaskruckenberg.github.io/tauri-docs-wip/development/inter-process-communication.html#error-handling