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

Make anyTranscodeFailure more descriptive (1.x branch) #1530

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions Sources/SwiftProtobuf/AnyMessageStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ internal class AnyMessageStorage {
case .contentJSON(let contentJSON, let options):
// contentJSON requires we have the type available for decoding
guard let messageType = Google_Protobuf_Any.messageType(forTypeURL: _typeURL) else {
throw BinaryEncodingError.anyTranscodeFailure
throw BinaryEncodingError.anyTypeURLNotRegistered(typeURL: _typeURL)
}
do {
// Decodes the full JSON and then discard the result.
Expand Down Expand Up @@ -429,7 +429,7 @@ extension AnyMessageStorage {
// binary value, so we're stuck. (The Google spec does not
// provide a way to just package the binary value for someone
// else to decode later.)
throw JSONEncodingError.anyTranscodeFailure
throw JSONEncodingError.anyTypeURLNotRegistered(typeURL: _typeURL)
}
let m = try messageType.init(serializedData: valueData, partial: true)
return try serializeAnyJSON(for: m, typeURL: _typeURL, options: options)
Expand Down
5 changes: 3 additions & 2 deletions Sources/SwiftProtobuf/BinaryEncodingError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
// -----------------------------------------------------------------------------

/// Describes errors that can occur when decoding a message from binary format.
public enum BinaryEncodingError: Error {
public enum BinaryEncodingError: Error, Equatable {
/// `Any` fields that were decoded from JSON cannot be re-encoded to binary
/// unless the object they hold is a well-known type or a type registered via
/// `Google_Protobuf_Any.register()`.
case anyTypeURLNotRegistered(typeURL: String)
/// An unexpected failure when deserializing a `Google_Protobuf_Any`.
case anyTranscodeFailure

/// The definition of the message or one of its nested messages has required
/// fields but the message being encoded did not include values for them. You
/// must pass `partial: true` during encoding if you wish to explicitly ignore
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftProtobuf/JSONEncodingError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
///
// -----------------------------------------------------------------------------

public enum JSONEncodingError: Error {
public enum JSONEncodingError: Error, Equatable {
/// Any fields that were decoded from binary format cannot be
/// re-encoded into JSON unless the object they hold is a
/// well-known type or a type registered with via
/// Google_Protobuf_Any.register()
case anyTranscodeFailure
case anyTypeURLNotRegistered(typeURL: String)
/// Timestamp values can only be JSON encoded if they hold a value
/// between 0001-01-01Z00:00:00 and 9999-12-31Z23:59:59.
case timestampRange
Expand Down