PSeitz / wana_kana_rust

Utility library for checking and converting between Japanese characters - Hiragana, Katakana - and Romaji
MIT License
70 stars 14 forks source link

Add APIs using `Result` with `thiserror` or `anyhow` crates instead of `panic` #16

Closed tats-u closed 1 month ago

tats-u commented 1 month ago

https://github.com/search?q=repo%3APSeitz%2Fwana_kana_rust%20panic&type=code

This library can panic and discourages other software from adopting this library.

https://github.com/PSeitz/wana_kana_rust/issues/13

e.g. https://github.com/orgs/meilisearch/discussions/532#discussioncomment-9999921

https://docs.rs/thiserror/latest/thiserror/ and https://docs.rs/anyhow/latest/anyhow/ are widely used to handle errors without panic.

New APIs like to_kana_safe() and to_romaji_safe() will be appreciated.

PSeitz commented 1 month ago

The library should never panic. Error's don't make sense imo, since it works on a best effort basis.

Here's how I addressed the issue:

  1. Fixed the original issue
  2. Added some proptests with random and semi random input to check for panics
  3. Checked the code for other potential panics
tats-u commented 1 month ago

Oh snap, looks like all of them are test code. Sorry to bother you.