Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove a panic in add_type_definition and add error contexts so resul… #2369

Merged
merged 1 commit into from
Jan 1, 2025

Conversation

mhammond
Copy link
Member

…ting errors make sense.

With this patch, output from errors looks something like:

  Caused by:
      0: adding function Function { name: "get_maybe_url", module_path: "uniffi_ext_types_lib", is_async: false, arguments: [Argument { name: "url", type_: Optional { inner_type: Custom { module_path: "custom_types", name: "Url", builtin: None } }, by_ref: false, optional: false, default: None }], return_type: Some(Optional { inner_type: Custom { module_path: "custom_types", name: "Url", builtin: None } }), ffi_func: FfiFunction { name: "uniffi_uniffi_ext_types_lib_fn_func_get_maybe_url", is_async: false, arguments: [], return_type: None, has_rust_call_status_arg: true, is_object_free_function: false }, docstring: None, throws: None, checksum_fn_name: "uniffi_uniffi_ext_types_lib_checksum_func_get_maybe_url", checksum: None }
      1: adding type Optional { inner_type: Custom { module_path: "custom_types", name: "Url", builtin: None } }
      2: adding optional type Custom { module_path: "custom_types", name: "Url", builtin: None }
      3: Custom { module_path: "custom_types", name: "Url", builtin: None } must have a resolved builtin

@mhammond mhammond requested a review from badboy December 26, 2024 20:54
@mhammond mhammond requested a review from a team as a code owner December 26, 2024 20:54
Copy link
Contributor

@bendk bendk left a comment

Choose a reason for hiding this comment

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

LGTM, I think the context message handling may be could be improved but I'm not sure. Either way this feels like an improvement to me.

@@ -111,7 +118,8 @@ impl TypeUniverse {
/// Add many [`Type`]s...
pub fn add_known_types(&mut self, types: TypeIterator<'_>) -> Result<()> {
for t in types {
self.add_known_type(t)?
self.add_known_type(t)
.with_context(|| format!("adding type {t:?}"))?
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these getting overridden by the parsing udl file... context? That what it seems like from the trybuild tests, but I'm not sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so:

Copy link
Member Author

Choose a reason for hiding this comment

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

oops:

It's gone from:

error: Failed to generate name: Invalid trait name: PartialEq
to:
error: Failed to generate name: parsing udl : Invalid trait name: PartialEq

which is redundant here, but I don't think is overriding anything.

Interresting note re messages - this has:

.add_known_types(defn.iter_types())
.with_context(|| format!("adding enum {defn:?}"))?;

which imo is nicer in the code, but worse in the errors. For some reason I don't like using the word "error" there:

.add_known_types(defn.iter_types())
.with_context(|| format!("error adding enum {defn:?}"))?;

but I'm torn

@mhammond mhammond merged commit 05778b1 into mozilla:main Jan 1, 2025
5 checks passed
@mhammond mhammond deleted the push-kkzkntkzszxk branch January 1, 2025 01:36
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.

2 participants