Fix TypeError in s3 error handler when Error.Message is None#10355
Open
omghante wants to merge 1 commit into
Open
Fix TypeError in s3 error handler when Error.Message is None#10355omghante wants to merge 1 commit into
omghante wants to merge 1 commit into
Conversation
S3-compatible endpoints (Ceph, MinIO, Hetzner) may return XML error responses with empty <Message></Message> elements. Python's ElementTree parses these as None, causing botocore to set Error.Message to None in the parsed response dict. The _is_sigv4_error_message() and _is_kms_sigv4_error_message() functions use the in operator to check if a substring exists in the message, which raises TypeError when the message is None. Use or-coalescing to normalize None values to empty strings before performing containment checks. Also guard the enhance_error_msg() body against None Message and missing Endpoint in the PermanentRedirect path. Fixes aws#10161
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.
Description
Fix
TypeError: argument of type 'NoneType' is not iterableinawscli/customizations/s3errormsg.pywhen S3-compatible endpoints return error responses with empty<Message></Message>XML elements.Fixes #10161
Root Cause
S3-compatible endpoints (Ceph RadosGW, Hetzner, MinIO) may return valid XML error responses with empty
<Message>elements. Python'sElementTreeparses empty elements asNone(i.e.,.text = None), and botocore's error parsing path in_replace_nodes()does not normalizeNoneto"". This causes the parsed response dict to contain{'Error': {'Message': None}}.The
_is_sigv4_error_message()and_is_kms_sigv4_error_message()functions then perform'substring' in None, which raises:TypeError: argument of type 'NoneType' is not iterable
Key Python gotcha:
.get('Message', '')returns the default''only when the key is absent. When the key exists with valueNone,.get()returnsNone.Changes
or ''coalescing in_is_sigv4_error_message(),_is_permanent_redirect_message(), and_is_kms_sigv4_error_message()to handleNonevalues safelyenhance_error_msg()body againstNoneMessage and missingEndpointin thePermanentRedirectcode pathNoneMessage,NoneCode, empty string Message, andPermanentRedirectwithNoneMessageTesting
pytest tests/unit/customizations/test_s3errormsg.py -v11 passedMessagecontent)Credit
Root cause analysis by @sfwester in #10161.