Skip to content

Commit

Permalink
return a wrapped error
Browse files Browse the repository at this point in the history
  • Loading branch information
qingyang-hu committed Dec 5, 2024
1 parent 701bd46 commit 4c20d77
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion internal/integration/client_side_encryption_prose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3111,7 +3111,7 @@ func TestClientSideEncryptionProse(t *testing.T) {

ceo := options.ClientEncryption().
SetKeyVaultNamespace(kvNamespace).
SetKmsProviders(fullKmsProvidersMap).
SetKmsProviders(kmsProviders).
SetTLSConfig(map[string]*tls.Config{dataKey.provider: tlsCfg})
clientEncryption, err := mongo.NewClientEncryption(keyVaultClient, ceo)
require.NoError(mt, err, "error on NewClientEncryption: %v", err)
Expand Down
5 changes: 1 addition & 4 deletions x/mongo/driver/crypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,7 @@ func (c *crypt) decryptKey(kmsCtx *mongocrypt.KmsContext) error {
res := make([]byte, bytesNeeded)
bytesRead, err := conn.Read(res)
if err != nil {
if kmsCtx.Fail() {
err = nil
}
return err
return kmsCtx.RequestError()
}

if err = kmsCtx.FeedResponse(res[:bytesRead]); err != nil {
Expand Down
9 changes: 6 additions & 3 deletions x/mongo/driver/mongocrypt/mongocrypt_kms_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ func (kc *KmsContext) createErrorFromStatus() error {
return errorFromStatus(status)
}

// Fail returns a boolean indicating whether the failed request may be retried.
func (kc *KmsContext) Fail() bool {
return bool(C.mongocrypt_kms_ctx_fail(kc.wrapped))
// RequestError returns the source of the network error for KMS requests.
func (kc *KmsContext) RequestError() error {
if bool(C.mongocrypt_kms_ctx_fail(kc.wrapped)) {
return nil
}
return kc.createErrorFromStatus()
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (kc *KmsContext) FeedResponse([]byte) error {
panic(cseNotSupportedMsg)
}

// Fail returns a boolean indicating whether the failed request may be retried.
func (kc *KmsContext) Fail() bool {
// RequestError returns the source of the network error for KMS requests.
func (kc *KmsContext) RequestError() error {
panic(cseNotSupportedMsg)
}

0 comments on commit 4c20d77

Please sign in to comment.