awslabs / aws-c-common

Core c99 package for AWS SDK for C. Includes cross-platform primitives, configuration, data structures, and error handling.
Apache License 2.0
262 stars 159 forks source link

Simplify error handling in XML API - BREAKING CHANGE #1043

Closed graebm closed 1 year ago

graebm commented 1 year ago

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.

This seems like a simple design. But the inconsistency in return type leads to errors being mistakenly swallowed. 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:

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 (https://github.com/awslabs/aws-c-auth/pull/40), then moved to public in aws-c-common (https://github.com/awslabs/aws-c-common/pull/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.

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