Skip to content

Conversation

paxbun
Copy link
Contributor

@paxbun paxbun commented Sep 6, 2025

Fixes #2636 by making ComponentInterface::is_name_used_as_error return true for unused external errors using all_component_interfaces introduced in #2612. self.errors.contains(name) || is still required for cases where library mode is not used, which is the reason why 4224423 has failed.

Why #2636 occurs

self.error.insert happens when the error enum itself is defined in the crate, or it is thrown from a function or a constructor. Since external errors are not defined in the crate, they are not registered through self.error.insert when it is not used. The check to determine whether an enum is an error requires an EnumMetadata, but EnumMetadata for external errors used in a variant of an enum is not being provided to CI.

@paxbun paxbun requested a review from a team as a code owner September 6, 2025 09:07
@paxbun paxbun requested review from mhammond and removed request for a team September 6, 2025 09:07
Copy link
Member

@mhammond mhammond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct to me, thanks! Some tests would be great though :)

@@ -1021,6 +1021,10 @@ impl ComponentInterface {

pub fn is_name_used_as_error(&self, name: &str) -> bool {
self.errors.contains(name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could just remove this?

Copy link
Contributor Author

@paxbun paxbun Sep 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! That part is still needed (as all_component_interfaces is set only in library mode) and removing it breaks some tests; would setting all_component_interfaces in non-library mode be better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right 😅 "library mode" has always seemed strange to me. What does "non library mode" mean with external types? Non library mode having only a clone of itself in all_component_interfaces seems fine too, but not worth it here i guess?

(part of the confusion is actually around udl generating rust scaffolding - that's "not library mode" - but also doesn't need all_component_interfaces. In terms of bindings, "not library mode" shouldn't be a thing)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't had a deep look at the UDL parsing part (as I'm primarily using library mode), but if you find it awkward that the library mode cloning CIs to populate all_component_interfaces, how about removing the grouping logic in library_mode::find_components? In UDL files, external types to be used are all declared again, and it seems the UDL parsing logic doesn't re-group the metadata at all...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UDL parsing is done for both scaffolding and bindings - ie, is used by library mode too. Further, individual crates can use both udl and macros - so I don't think we can just remove the grouping in that way.

Comment on lines +231 to +235
#[derive(uniffi::Error)]
pub enum ContainsExternalError {
ExternalError(NotToThrowError),
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhammond This is the case that @dani-garcia mentioned; should I add cases like where NotToThrowError is used as parameters or record properties for better test coverage?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhammond This is the case that @dani-garcia mentioned;

sorry, I've lost some context - mentioned where?

should I add cases like where NotToThrowError is used as parameters or record properties for better test coverage?

I guess that can't hurt, but probably isn't strictly necessary - just a test which fails without your patch but works with it seems fine to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong Android error name when using nested external error
2 participants