fefit/rphtml

Reduce potential `panic` usage

Opened this issue · 1 comments

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 commented

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.