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:
While this works fine in most cases, it's not an ideal design for several reasons:
In theory, the same error code may be used by different C libraries to represent different error causes. Moreover, users can't know which library the error code belongs to, as that information is not meant to be made available on the error struct.
A set of error causes is more idiomatically represented in Rust by an enum type, rather than a raw integer.
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.
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 aerror_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.