uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

`unkown throw type` error when composing multiple crate

Open setoelkahfi opened this issue 1 year ago • 5 comments

I have a networking crate that depends on a crate_error_codes crate and uses cargo swift to generate the swift package of the networking crate. I got an error while generating Swift binding with the cargo swift package command:

unknown throw type: Some(External { module_path: "crate_error_codes", name: "ErrorResponse", namespace: "crate_error_codes", kind: DataClass, tagged: false })

But I ran the same command directly from the crate_error_codes itself without issue. Below is my data structure:


#[derive(Serialize, Deserialize, Debug, Error)]
#[tsync]
pub enum ErrorResponse {
    Unknown { error_code: ErrorCode, message: String },
    UserNotFound { error_code: ErrorCode, message: String },
    // continues ...
}

impl Error for ErrorResponse {}

impl Display for ErrorResponse {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        write!(f, "{:?}", self)
    }
}

#[repr(i32)]
#[derive(Serialize_repr, Deserialize_repr, Debug, EnumIter, Enum)]
#[tsync]
pub enum ErrorCode {
    Unknown = 0,
    //User-defined error codes start from 1000
    UserNotFound = 1000,
    // continues ....


setup_scaffolding!();

Cargo.toml

[package]
name = "crate_error_codes"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["lib", "cdylib", "staticlib"]
name = "crate_error_codes"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_repr = "0.1"
tsync = "1"
strum = "0.26"
strum_macros = "0.26"
uniffi = "0.27"

[build-dependencies]
uniffi = { version = "0.27", features = ["build"] }
[package]
name = "crate_networking"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["lib", "staticlib"]
name = "crate_networking"

[dependencies]
reqwest = { version = "0.12", features = ["json"] }
uniffi = { version = "0.27", features = ["tokio"] }
log = "^0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
url-builder = "0.1.1"

# Local crates
crate_error_codes = { path = "./../../lib/crate_error_codes" }
crate_models = { path = "./../../lib/crate_models" }

[build-dependencies]
uniffi = { version = "0.27", features = ["build"] }

Any pointers?

setoelkahfi avatar Aug 29 '24 12:08 setoelkahfi