ComunidadAylas / vorbis-rs

🔊 Rust bindings for the best-in-breed C libraries of the Vorbis audio codec and Ogg container encapsulation.
https://crates.io/crates/vorbis_rs
BSD 3-Clause "New" or "Revised" License
16 stars 4 forks source link

Return idiomatic error enums instead of low-level library error codes #7

Closed AlexTMjugador closed 1 year ago

AlexTMjugador commented 1 year ago

Currently, the internal macro that converts low-level C library error codes to an user-facing Result just passes through error codes returned by C functions, which users can compare with some crate constants to know the precise error cause:

https://github.com/ComunidadAylas/vorbis-rs/blob/5aa716074616d3bf88f4d4ff91015ee86faadcd9/packages/vorbis_rs/src/common/error.rs#L53-L65

While this works fine in most cases, it's not an ideal design for several reasons:

Therefore, a welcome improvement would be replacing the error_code field with a error_cause field, which relates the library that caused the error with its actual cause. This would complicate the error handling logic significantly, but I think it's worth it for end usage.