Skip to content

fix: preserve root-cause errors in KMSMasterKey exception chaining#809

Merged
lucasmcdonald3 merged 1 commit into
masterfrom
fix/kms-exception-chaining-774
Jun 23, 2026
Merged

fix: preserve root-cause errors in KMSMasterKey exception chaining#809
lucasmcdonald3 merged 1 commit into
masterfrom
fix/kms-exception-chaining-774

Conversation

@kessplas

@kessplas kessplas commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Copy of #807 so that CI can run with the correct permissions.

KMSMasterKey caught boto3 ClientError (and KeyError) on the generate_data_key, encrypt, and decrypt calls and re-raised its own GenerateKeyError / EncryptKeyError / DecryptKeyError without chaining the original exception. Because the re-raise used a bare "raise SomeError(...)" instead of "raise SomeError(...) from error", the re-raised exception's cause was None and the underlying KMS failure (for example an AccessDeniedException) was dropped from the traceback. Callers were left debugging in the dark with only the generic "unable to ... data key" message.

Add "from error" at the three boto-call catch sites so the original exception is preserved as cause. The raised exception type and message are unchanged, so this is backward compatible; it only adds the chained cause to the traceback.

Includes regression tests asserting cause is the original ClientError for the generate, encrypt, and decrypt paths.

Fixes #774

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Check any applicable:

  • Were any files moved? Moving files changes their URL, which breaks all hyperlinks to the files.

KMSMasterKey caught boto3 ClientError (and KeyError) on the
generate_data_key, encrypt, and decrypt calls and re-raised its own
GenerateKeyError / EncryptKeyError / DecryptKeyError without chaining the
original exception. Because the re-raise used a bare "raise SomeError(...)"
instead of "raise SomeError(...) from error", the re-raised exception's
__cause__ was None and the underlying KMS failure (for example an
AccessDeniedException) was dropped from the traceback. Callers were left
debugging in the dark with only the generic "unable to ... data key"
message.

Add "from error" at the three boto-call catch sites so the original
exception is preserved as __cause__. The raised exception type and message
are unchanged, so this is backward compatible; it only adds the chained
cause to the traceback.

Includes regression tests asserting __cause__ is the original ClientError
for the generate, encrypt, and decrypt paths.

Fixes #774

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@kessplas kessplas requested a review from a team as a code owner June 9, 2026 21:31
@lucasmcdonald3 lucasmcdonald3 merged commit 6b7007a into master Jun 23, 2026
535 of 605 checks passed
@lucasmcdonald3 lucasmcdonald3 deleted the fix/kms-exception-chaining-774 branch June 23, 2026 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KMSMasterKey swallows root cause errors

3 participants