#error #eyre #traits #don-t #dealing #tauri

string-eyre

处理不希望使用 eyre 的错误时的便捷特性

1 个不稳定版本

0.1.0 2021年11月23日

#1464Rust 模式

MIT/Apache

5KB

string-eyre

这发生在你身上了吗?

error[E0599]: the method `wrap_err` exists for enum `Result<(), tauri::Error>`, but its trait bounds were not satisfied
   --> src/main.rs:60:6
    |
60  |     .wrap_err("error while running tauri application")?;
    |      ^^^^^^^^
    |
   ::: /home/michcioperz/.cargo/registry/src/github.com-1ecc6299db9ec823/tauri-1.0.0-beta.8/src/error.rs:10:1
    |
10  | pub enum Error {
    | --------------
    | |
    | doesn't satisfy `tauri::Error: Sync`
    | doesn't satisfy `tauri::Error: eyre::context::ext::StdError`
    |
   ::: /home/michcioperz/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:503:1
    |
503 | pub enum Result<T, E> {
    | --------------------- doesn't satisfy `_: WrapErr<(), tauri::Error>`
    |
    = note: the following trait bounds were not satisfied:
            `tauri::Error: eyre::context::ext::StdError`
            which is required by `Result<(), tauri::Error>: WrapErr<(), tauri::Error>`
            `tauri::Error: Sync`
            which is required by `Result<(), tauri::Error>: WrapErr<(), tauri::Error>`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `app` due to previous error

有时你会非常累,然后决定,好吧,也许我需要将错误转换为字符串

    .map_err(|e| e.to_string())

这工作得很好,除非错误无法转换为字符串,这时你会变得很生气,然后

    .map_err(|e| format!("{:?}", e))

但 String 事实上并不是一个错误类型,所以 eyre 正当地不会将其视为错误类型,所以你实际上想要

    .map_err(|e| eyre!("{:?}", e))

可能更多的人会对我大喊大叫,但我想有简写形式,这样我就不必一遍又一遍地输入这个异端,而是可以写

    .debug_to_eyre()

依赖关系

~180KB