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

Implement Error and ErrorCode for Rust #4743

Merged
merged 3 commits into from
Jan 14, 2025

Conversation

youyuanwu
Copy link
Contributor

@youyuanwu youyuanwu commented Jan 13, 2025

Description

Rust Api typically returns Result<T,Error> where Error contains the error details of the api failure.
This PR implements ErrorCode enum type which can be easily converted from FFI error numbers, and Error type which produces decent error message when printed or formated. For example:

        let err = Error::new(ErrorCode::QUIC_ERROR_ABORTED);
        assert_eq!(format!("{err}"), "QUIC_ERROR_ABORTED (0x80004004)");

Changes all Apis to return Result<T,Error> instead of Result<T,u32> and removed all redundant code.

Testing

Added unit tests for error code conversion and formating.

Documentation

NA

@youyuanwu youyuanwu marked this pull request as ready for review January 13, 2025 05:50
@youyuanwu youyuanwu requested a review from a team as a code owner January 13, 2025 05:50
src/error.rs Show resolved Hide resolved
Copy link

codecov bot commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.85%. Comparing base (39c6b52) to head (8064d58).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4743      +/-   ##
==========================================
+ Coverage   85.74%   85.85%   +0.10%     
==========================================
  Files          56       56              
  Lines       17378    17400      +22     
==========================================
+ Hits        14901    14938      +37     
+ Misses       2477     2462      -15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/error.rs Show resolved Hide resolved
@nibanks nibanks enabled auto-merge (squash) January 14, 2025 01:07
@nibanks nibanks added the Language: Rust Related to the Rust interop layer label Jan 14, 2025
@nibanks nibanks merged commit ba795e0 into microsoft:main Jan 14, 2025
490 checks passed
@youyuanwu youyuanwu deleted the users/youyuanwu/error-types branch January 14, 2025 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Language: Rust Related to the Rust interop layer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants