-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Moving XML parser from aws-c-auth into aws-c-common #674
Merged
Conversation
This file contains 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
justinboswell
approved these changes
Jul 30, 2020
…s changes to tests to be more consistent.
I know it's a lot more work, but should these go into a new repo, instead of aws-c-common? |
rccarper
force-pushed
the
moving-xml-parser
branch
from
July 31, 2020 18:08
16a473e
to
f8885a8
Compare
justinboswell
approved these changes
Jul 31, 2020
graebm
added a commit
that referenced
this pull request
Jul 18, 2023
**Issue:** It's hard to report errors with the current API. Errors are being accidentally ignored, and some errors are never checked (perhaps because it was too much effort?). **Diagnosis:** The current callback returns `bool` of whether to continue parsing, rather than our typical `int/AWS_OP_SUCCESS/aws_raise_error()` [error handling](https://github.com/awslabs/aws-c-common/blob/b1ef77c1790a8776b58ae5ae57f90e9534b78991/README.md#error-handling). This seems like a simple design. But the inconsistency in return type leads to errors being [mistakenly swallowed](awslabs/aws-c-s3#330 (comment)). And it makes it hard when you do want to "bubble up" an error from the callback. Callbacks needs to store a custom `error_code` in their `user_data` to report an error. Most callbacks never bothered to do this, maybe because it was extra work? **Description of changes:** - XML traversal callback returns `int` instead of `bool`. - If a callback fails, the whole parse() fails. - You can no longer stop parsing without causing failure. But in nearly all use-cases we were stopping due to error. I found 1 case where we stopped because we found what we were looking for. But in this case, it didn't really hurt to continue parsing. The reduced complexity seemed worth the change. - Remove ~aws_xml_parser_new(), aws_xml_parser_destroy(), aws_xml_parser_parse()~, replace with `aws_xml_parse()`. - The new() and destroy() calls were unnecessary. Removing them simplifies use. - `aws_xml_node_get_name()` just returns `aws_byte_cursor()`, instead of ~int~ - This can't fail. Changing the signature simplifies use. - Raise `AWS_ERROR_INVALID_XML` instead of ~AWS_ERROR_MALFORMED_INPUT_STRING~ - This change is more wishy-washy. It seemed useful to get this new, more specific, error code if it bubbling up from deep within some larger operation, like an S3 meta-request. **API BREAK:** We don't know any external uses of this API, so it seems safe to change. The API is only intended for internal use by the aws-c libraries, which are being fixed up now. This API was quickly written as private code in aws-c-auth (awslabs/aws-c-auth#40), then moved to public in aws-c-common (#674) when aws-c-s3 also needed to parse XML. The fact that it was originally private is why this API didn't get more scrutiny originally.
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 of changes:
Adding XML parser from aws-c-auth. Made minor changes for naming, also made a couple of types opaque and added accessors.
Justification for leaving aws_xml_attribute visible: it seems reasonable that we could expose an attribute as a name/value pair, and that this would be less awkward than needing a get-attribute, get-name, get-value each time when needing to use a single attribute. (But I'm open to making this opaque too!)
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.