Skip to content
New issue

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

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

Already on GitHub? # to your account

Refactor Flatten to first flatten the tree and then filter the results #16

Closed
Southclaws opened this issue Nov 20, 2022 · 3 comments
Closed

Comments

@Southclaws
Copy link
Owner

Currently, the implementation of Flatten is a bit more complex than it needs to be. This is partly due to the way the loop mutates next in a couple of places and also doubly calls Unwrap and re-assigns err twice.

This could be simplified by first running the Unwrap loop to product a simple slice of errors. Then, once there's a slice, it would be easier to do the filtering with lookahead/lookbehind instead of (what is essentially) double step/next iterations etc.

@spearson78
Copy link

I have a modified version of flatten in my repo (https://github.com/spearson78/fault/tree/floc) that doesn't have look ahead but is functionally equivalent. I was trying to make auto generated location optional so that a library can generate an error with a location that corresponds to the caller rather than a random line of code in the library. This reduces the amount of wrapping needed in user code.

@Southclaws
Copy link
Owner Author

This would be good to explore as a solution. I'm going to make some changes to the flatten call soon so it's at least easier to make simple changes/additions to.

@Southclaws
Copy link
Owner Author

Check out the latest release (v0.5.0) where I've rewritten Flatten to be more smart about duplicate nested error messages.

There's still some work to do around locations, it may be worth storing a full stack trace with each error step and unpacking the most logical frame when the error is flattened. Anyway, can move discussion for this to another issue.

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

No branches or pull requests

2 participants