Skip to content

Improve Errors#152

Merged
alice-i-cecile merged 16 commits intoDioxusLabs:mainfrom
TheDestroyer19:main
Jun 11, 2022
Merged

Improve Errors#152
alice-i-cecile merged 16 commits intoDioxusLabs:mainfrom
TheDestroyer19:main

Conversation

@TheDestroyer19
Copy link
Copy Markdown
Contributor

Objective

Replaces taffy::Error with taffy::NodeNotFoundError to make code much more legible. Also adds taffy::ChildOperationError so that remove_child_at_index, replace_child_at_index, and child_at_index can return an error instead of panicing.

Fixes #100 #104

Feedback wanted

I'm not happy with the name of ChildOperationError. It feels a little vague to me. Is it fine, or is there possibly a better name for it?

Also, I'm not sure I should have flattened NodeNotFoundError into a tuple struct.

@alice-i-cecile alice-i-cecile added the usability Make the library more comfortable to use label Jun 11, 2022
src/lib.rs Outdated
pub struct NodeNotFoundError(pub node::Node);

#[cfg(feature = "std")]
impl Display for NodeNotFoundError {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we should just pull in thiserror and feature-gate it behind std. It's a much nicer way to define these error strings.

src/lib.rs Outdated
child_count: usize,
},
///The [`Node`](node::Node) was not found in the [`Taffy`] instance
NodeNotFoundError(NodeNotFoundError),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't love nesting these errors like this, but until we have "enum variants are types" this is a better design to keep the function signatures of most of the operations cleaner.

Copy link
Copy Markdown
Collaborator

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Thanks! First round of feedback is up :) Some suggestions on naming mostly.

I'd like feedback on whether or not we should use thiserror.

The API is much nicer, but it pulls in some relatively heavy proc-macro crates which might hurt compile times.

Copy link
Copy Markdown
Collaborator

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Almost ready now.

@alice-i-cecile
Copy link
Copy Markdown
Collaborator

Excellent work; thanks for being so responsive to reviews.

@alice-i-cecile alice-i-cecile enabled auto-merge (squash) June 11, 2022 18:17
@alice-i-cecile alice-i-cecile merged commit 712df30 into DioxusLabs:main Jun 11, 2022
@TheDestroyer19
Copy link
Copy Markdown
Contributor Author

Thank you for being quick to provide feedback. I appreciate it

@Weibye Weibye mentioned this pull request Jun 12, 2022
jkelleyrtp pushed a commit that referenced this pull request Oct 10, 2022
* Added checks for child_index out of bounds

* slightly better descriptions

* updated RELEASES.md

* Changed TaffyError back to Error

* split error type into two

* fixed error in git merge

* updated RELEASES.md file

* cargo fmt

* moved errors into error module, and gave them better names

* Split InvalidChild::InvalidNode into two

* updated RELEASES.md

* cargo fmt

* more changes to RELEASES.md

Co-authored-by: Alice Cecile <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

usability Make the library more comfortable to use

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Give taffy::Error a more useful name

2 participants