Skip to content

Wrong Android error name when using nested external error #2636

@dani-garcia

Description

@dani-garcia

I've been trying the latest merged changes that add support for external errors on Android, and I've found that UniFFI is not correctly doing the *Error to *Exception rename when the external error is being used inside another error type:

// This error is defined in crate-a

#[derive(uniffi::Error)]
pub enum TestError {
    BadThingsHappened(String),
    ErrorFromCrateB(crate_b::CrateBError),
}

// This error is defined in crate-b
#[derive(uniffi::Error)]
pub enum CrateBError {
    CrateBScrewedUp(u64),
}

If I check the generated bindings, I can see that the rename is done correctly in crate_b.kt:

sealed class CrateBException: kotlin.Exception() {
...
}

But when it gets imported in crate_a.kt, the rename doesn't happen:

import uniffi.crate_b.CrateBError    // <!--- Compile error here

sealed class TestException: kotlin.Exception() {
    class BadThingsHappened(
        val v1: kotlin.String
        ) : TestException() { ... }
    
    class ErrorFromCrateB(
        val v1: CrateBError    // <!--- Compile error here
        ) : TestException() { ...  }

If I manually rename the CrateBError to CrateBException in the file everything works correctly, so this seems to only be a bug in the template generation. Let me know if you need more info, I have a repro here if it's helpful: https://github.com/dani-garcia/uniffi-android-error-repro

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions