Skip to content

Conversation

@smaye81
Copy link
Member

@smaye81 smaye81 commented Sep 12, 2023

This updates the repo to use the latest conformance image, which uses the new organization on Dockerhub as well as the new proto packages (connectrpc.conformance.v1 instead of grpc.testing).

As a part of this update, this attempts a fix at decoding the ErrorDetails value, which is returned as a base64-encoded string. The Connect protocol states that implementations should emit unpadded values and that downstream implementations should accept both padded and unpadded values. This adds padding to this string if needed as part of the ConnectError decode logic.

Comment on lines 76 to 92
public init(from decoder: Swift.Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

// Read the base64-encoded payload and then pad if needed
let encodedPayload = try container.decode(String.self, forKey: .payload)
let padded = encodedPayload.padding(
toLength: ((encodedPayload.count+3)/4)*4,
withPad: "=",
startingAt: 0
)

self.init(
type: try container.decodeIfPresent(String.self, forKey: .type) ?? "",
payload: Data(base64Encoded: padded)
)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

@rebello95 Here is the padding fix I mentioned.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do tests cover receiving both a padded and unpadded error?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean the conformance suite? If so, no, they don't account for that. But probably a good one to add when it's refactored.

let container = try decoder.container(keyedBy: CodingKeys.self)

// Read the base64-encoded payload and then pad if needed
let encodedPayload = try container.decode(String.self, forKey: .payload)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be a decodeIfPresent? This is changing behavior to throw if payload is omitted

Copy link
Member Author

Choose a reason for hiding this comment

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

Definitely should. Fixed.

Comment on lines 76 to 92
public init(from decoder: Swift.Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

// Read the base64-encoded payload and then pad if needed
let encodedPayload = try container.decode(String.self, forKey: .payload)
let padded = encodedPayload.padding(
toLength: ((encodedPayload.count+3)/4)*4,
withPad: "=",
startingAt: 0
)

self.init(
type: try container.decodeIfPresent(String.self, forKey: .type) ?? "",
payload: Data(base64Encoded: padded)
)
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do tests cover receiving both a padded and unpadded error?

smaye81 and others added 5 commits September 12, 2023 16:39
Co-authored-by: Michael Rebello <me@michaelrebello.com>
…ce.swift

Co-authored-by: Michael Rebello <me@michaelrebello.com>
Base automatically changed from sayers/fix_streaming_error_after_response to main September 12, 2023 20:57
@smaye81 smaye81 marked this pull request as ready for review September 12, 2023 21:00
smaye81 and others added 2 commits September 12, 2023 18:24
Co-authored-by: Michael Rebello <me@michaelrebello.com>
Co-authored-by: Michael Rebello <me@michaelrebello.com>
@rebello95
Copy link
Collaborator

Would be nice to add tests for unpadded ConnectErrors in a follow-up PR

@smaye81
Copy link
Member Author

smaye81 commented Sep 12, 2023

Agreed. I'll put a PR together for that. Thanks for reviewing!

@smaye81 smaye81 merged commit 2f622ba into main Sep 12, 2023
@smaye81 smaye81 deleted the sayers/use_connectrpc_pkg branch September 12, 2023 22:44
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.

3 participants