[KeyManager] End-to-end FFI error handling standardization#722
Merged
NilanjanDaw merged 8 commits intogoogle:mainfrom Mar 23, 2026
Merged
[KeyManager] End-to-end FFI error handling standardization#722NilanjanDaw merged 8 commits intogoogle:mainfrom
NilanjanDaw merged 8 commits intogoogle:mainfrom
Conversation
2345191 to
53e2346
Compare
Replaces negative `i32` error codes and ad-hoc error enums with the standardized `keymanager.Error` protobuf enum across the Rust backend, C-bindings, and Go HTTP server. - Rust FFI explicitly returns `Error` enum. - Updates `cbindgen.toml` configurations and C headers to export `Error`. - Go CGO wrappers map `Error` to standard errors or `FFIError`. - `server.go` translates these standardized FFI errors to standard HTTP status codes. - Removes redundant `types.go` error aliases in the Go packages.
atulpatildbz
approved these changes
Mar 23, 2026
pgonda
reviewed
Mar 23, 2026
| pubkeyLen, | ||
| ); rc != 0 { | ||
| return uuid.Nil, nil, fmt.Errorf("key_manager_generate_kem_keypair failed with code %d", rc) | ||
| ); keymanager.Status(rc) != keymanager.Status_STATUS_SUCCESS { |
Collaborator
There was a problem hiding this comment.
This is gonna get old.
Should you add a .ok() or similar method for:
if !keymanager.Status(rc).ok() {
...
}
pgonda
reviewed
Mar 23, 2026
| case errors.Is(err, keymanager.Status_STATUS_UNAUTHENTICATED): | ||
| return http.StatusUnauthorized | ||
| case errors.Is(err, keymanager.Status_STATUS_ALREADY_EXISTS): | ||
| return http.StatusConflict |
Collaborator
There was a problem hiding this comment.
This is fine. Once you update to gRPC service this gets much easier
pgonda
approved these changes
Mar 23, 2026
Collaborator
pgonda
left a comment
There was a problem hiding this comment.
Approval but please have someone give the rust code a quick look
53e2346 to
7fea15e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR performs a comprehensive refactoring of the
KeyManagercomponent to utilize the standardizedkeymanager.StatusProtobuf enum across all layers of the system. It replaces legacy negativei32error codes and ad-hocerrorenums with a unified, type-safeStatusreporting mechanism that spans Rust, C, and Go.Key Changes
KeyCustodyCorein bothkey_protection_serviceandworkload_serviceto return the Status enum directly.ffi_callandffi_call_i32helpers introduced in Part 1.Statusproto.kps_key_custody_core.handws_key_custody_core.hto returnStatusinstead ofint32_t.ToStatus()helper.httpStatusFromErrorin the Go server to automatically map standardized FFI errors to appropriate HTTP status codes (e.g.,ERROR_NOT_FOUND→404 Not Found,ERROR_INVALID_ARGUMENT→400 BadRequest).types.goto maintain a single source of truth.ensure consistent error messages (e.g.,
"FFI error: ERROR_NOT_FOUND").