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

Reduce potential panic usage #3

Open
DjakaTechnology opened this issue Jun 11, 2023 · 1 comment
Open

Reduce potential panic usage #3

DjakaTechnology opened this issue Jun 11, 2023 · 1 comment

Comments

@DjakaTechnology
Copy link

In rust if we panicked, everything's break. There's no way to work around that, at least in straightforward manners.

Since it's a library, the user cannot predictably do stuff safely because the library can panic and user cannot handle it at all

@fefit
Copy link
Owner

fefit commented Jun 18, 2023

Sorry for the late reply and thanks for your advice.

I have checked the code and i have used panic in four palces, thoes panics are used in the following situations:

  1. Some codes that only used by the library itself, here, the panic is more like the assert, in order to make sure that some internal data can match the requirements. Maybe assert is better, i will update them in the next version.

  2. Some APIs cannot be called under certain data conditions, even if an exception is returned to the developer, it is not easy to do further processing.

This is my understanding of some situations where using panic to throw an error is more logical than returning an exception, maybe my understanding is not very thorough and there may be a better way to deal with it. If you have good suggestions, please feel free to point them out. Thanks again for your feedback.

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

2 participants