Skip to content
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

Fix compilation error for older gcc #3220

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,10 @@ namespace Aws

protected:
const Aws::Utils::Json::JsonValue& GetJsonPayloadFromError(const AWSError<CoreErrors>&) const;
AWSError<CoreErrors> MarshallHelper(const Aws::String& exceptionName, const Aws::String& message) const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so something i cant help but notice is that that JsonErrorMarshallerQueryCompatible::Marshall and JsonErrorMarshaller::Marshall are more or less copy and pasted code, which is why you have to invoke the parent class of JsonErrorMarshaller. instead we should try to make this more DRY and not have copy and pasted code and this eliminates the need for the child class to access the parents class, parent class. i.e. we could make a inherited callback.

struct Error{};
struct Response{};

class JsonSerializer {
public:
  Error Marshall(Response response) {
    auto error = ParseResponse(response);
    inheritedCallbacks(error, response);
    return error;
  }

protected:
  std::function<void(Error& error, Response& response)> inheritedCallbacks{};
private:
  Error ParseResponse(Response response);
};

class JsonQueryCompatible : public JsonSerializer {
public:
  JsonQueryCompatible() {
    inheritedCallbacks = [](Error& error, Response& response) {
      //custom error parsing
    };
  }
}

this way we avoid parsing something twice, and we contain the new code to ONLY be the bit about query compatible traits

};

class AWS_CORE_API JsonErrorMarshallerQueryCompatible : public JsonErrorMarshaller {
using AWSErrorMarshaller::Marshall;

public:
/**
* Converts an exceptionName and message into an Error object, if it
Expand Down
7 changes: 5 additions & 2 deletions src/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ AWSError<CoreErrors> AWSErrorMarshaller::FindErrorByHttpResponseCode(Aws::Http::
{
return CoreErrorsMapper::GetErrorForHttpResponseCode(code);
}
AWSError<CoreErrors> JsonErrorMarshaller::MarshallHelper(const Aws::String& exceptionName, const Aws::String& message) const {
return AWSErrorMarshaller::Marshall(exceptionName, message);
}

AWSError<CoreErrors> JsonErrorMarshallerQueryCompatible::Marshall(const Aws::Http::HttpResponse& httpResponse) const {
Aws::StringStream memoryStream;
Expand All @@ -266,9 +269,9 @@ AWSError<CoreErrors> JsonErrorMarshallerQueryCompatible::Marshall(const Aws::Htt
: "");

if (httpResponse.HasHeader(ERROR_TYPE_HEADER)) {
error = AWSErrorMarshaller::Marshall(httpResponse.GetHeader(ERROR_TYPE_HEADER), message);
error = JsonErrorMarshaller::MarshallHelper(httpResponse.GetHeader(ERROR_TYPE_HEADER), message);
} else if (payloadView.ValueExists(TYPE)) {
error = AWSErrorMarshaller::Marshall(payloadView.GetString(TYPE), message);
error = JsonErrorMarshaller::MarshallHelper(payloadView.GetString(TYPE), message);
} else {
error = FindErrorByHttpResponseCode(httpResponse.GetResponseCode());
error.SetMessage(message);
Expand Down
Loading