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

map_err is stack hungry #2326

Open
Henry-E opened this issue Dec 20, 2022 · 0 comments
Open

map_err is stack hungry #2326

Henry-E opened this issue Dec 20, 2022 · 0 comments

Comments

@Henry-E
Copy link

Henry-E commented Dec 20, 2022

There's wide usage of map_err in a variety of functions. It's mostly used to make sure that the correct account name is attached to an error. This is very useful but unfortunately in some cases it caused stack overflow which we solved by using a lazy eval and just matched the result #2313 .

From the rust docs for ok_or and ok_or_else

Arguments passed to ok_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use ok_or_else, which is lazily evaluated.

However there is no ok_or_else_map_err function, so we might have to make one that copies the functionality of the match statements and replace the map_err instances with this new function instead. It would look cleaner using our own custom function instead of writing out the length match statement everywhere anyway.

It's possible this won't be needed long term if people don't run into many stack errors but it's worth being aware of the issue and a potential solution if the need arises.

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

No branches or pull requests

1 participant