Skip to content

Conversation

@jprendes
Copy link
Contributor

This pull request adds a set of ergonomic error handling utilities to the src/hyperlight_guest/src/error.rs module, making it easier to attach context and custom error codes to errors in guest code. The changes include a new trait for contextual error conversion, implementations for Option and Result, two macros for concise error handling, and comprehensive unit tests to ensure correct behavior.

Error handling improvements:

  • Added the GuestErrorContext trait, which allows attaching context and error codes to Option and Result types, making it easier to convert them into rich error types (HyperlightGuestError).
  • Implemented GuestErrorContext for both Option<T> and Result<T, E>, enabling context-aware error conversion for these types.

Convenience macros for error handling:

  • Introduced the bail! macro to immediately return an error with a message and optional error code, and the ensure! macro to assert conditions and return errors if the condition fails.

Testing and validation:

  • Added a suite of unit tests that thoroughly verify the behavior of the new trait implementations and macros, ensuring reliability and correctness.

Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
@jprendes jprendes added kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. area/API Related to the API or public interface labels Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/API Related to the API or public interface kind/enhancement For PRs adding features, improving functionality, docs, tests, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant