Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
080185c
Sources/DataConnectError.swift: add classes to support partial errors.
dconeybe Feb 27, 2025
d5b1f19
Update DataConnectError.swift
aashishpatil-g Feb 28, 2025
3f277ce
DataConnectError.swift: minor tweaks from offline discussion
dconeybe Mar 3, 2025
c3cef5a
DataConnectError.swift: remove message string parameter
dconeybe Mar 3, 2025
3a03ef9
DataConnectError.swift: move OperationFailureResponse.ErrorInfo to to…
dconeybe Mar 3, 2025
23d76fb
Merge remote-tracking branch 'origin/main' into PartialErrors
dconeybe Mar 14, 2025
ad7cc64
DataConnectError.swift: update to match api proposal
dconeybe Mar 14, 2025
477e464
get it to build
dconeybe Mar 14, 2025
7ab5f83
PartialErrorsDemo.swift added
dconeybe Mar 14, 2025
f55305a
PartialErrorsDemo.swift: add usage of decodedData() to demo its use.
dconeybe Mar 14, 2025
98faec4
Updates matching API review and Refactored Errors
aashishpatil-g Mar 21, 2025
e29553c
Style Fixes
aashishpatil-g Mar 21, 2025
c763b2d
Remove whitespace from gql file
aashishpatil-g Mar 21, 2025
2a52e58
Re-add copyright notice to generated code
aashishpatil-g Mar 24, 2025
255d8dd
Unnest PathSegment definition
aashishpatil-g Mar 24, 2025
a763f9c
Rename PathSegment to DataConnectPathSegment to match other platforms
aashishpatil-g Mar 24, 2025
cd2cc5a
Cleanup post refactor (removed old `kind` var)
aashishpatil-g Mar 25, 2025
0e717a9
Convert vars to lets
aashishpatil-g Mar 25, 2025
8ddbe53
Change `cause` to `underlyingError`
aashishpatil-g Mar 25, 2025
72c1ac1
Make boxed error accessible
aashishpatil-g Mar 26, 2025
4d78594
Add Unit test to confirm domain error carries through the boxed type
aashishpatil-g Mar 26, 2025
95fc74e
Style checks
aashishpatil-g Mar 26, 2025
8bc19e7
Remove DataConnectError conformance
aashishpatil-g Mar 26, 2025
20d34b1
Nick feedback
aashishpatil-g Mar 27, 2025
92c1aec
fix copyright year
aashishpatil-g Mar 27, 2025
0fc0b63
Comment feedback fix
aashishpatil-g Mar 27, 2025
1c41f41
Documentation fixes.
aashishpatil-g Mar 27, 2025
0aafe10
More documentation fixes
aashishpatil-g Mar 27, 2025
c294d70
Yet more doc fixes
aashishpatil-g Mar 27, 2025
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
Prev Previous commit
Next Next commit
get it to build
  • Loading branch information
dconeybe committed Mar 14, 2025
commit 477e464ee6a26aafcb655b83efcc204d3a356571
18 changes: 14 additions & 4 deletions Sources/DataConnectError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ public enum DataConnectError: Error {

// The data and errors sent to us from the backend in its response.
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
public struct OperationFailureResponse {
public protocol OperationFailureResponse {
// JSON string whose value is the "data" property provided by the backend in its response
// payload; may be `nil` if the "data" property was not provided in the backend response and/or
// was `null` in the backend response.
public let jsonData: String?
var jsonData: String? { get }

// The list of errors in the "error" property provided by the backend in its response payload;
// may be empty if the "errors" property was not provided in the backend response and/or was an
// empty list in the backend response.
public let errorInfoList: [OperationFailureResponseErrorInfo]
var errorInfoList: [OperationFailureResponseErrorInfo] { get }

// Returns `jsonData` string decoded into the given type, if decoding was successful when the
// operation was executed. Returns `nil` if `jsonData` is `nil`, if `jsonData` was _not_ able to
Expand All @@ -56,7 +56,17 @@ public struct OperationFailureResponse {
//
// This function does _not_ do the decoding itself, but simply returns the decoded data, if any,
// that was decoded at the time of the operation's execution.
public func decodedData<Data: Decodable>(asType: Data.Type = Data.self) -> Data?
func decodedData<Data: Decodable>(asType: Data.Type) -> Data?
}

struct OperationFailureResponseImpl : OperationFailureResponse {
public let jsonData: String?

public let errorInfoList: [OperationFailureResponseErrorInfo]

func decodedData<Data: Decodable>(asType: Data.Type = Data.self) -> Data? {
return nil;
}
}

// Information about an error provided by the backend in its response.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Internal/CodableHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Int64CodableConverter: CodableConverter {
}

guard let int64Value = Int64(input) else {
throw DataConnectError.decodeFailed
throw DataConnectError.appNotConfigured
}
return int64Value
}
Expand Down
35 changes: 29 additions & 6 deletions Sources/Internal/GrpcClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,16 @@ actor GrpcClient: CustomStringConvertible {
DataConnectLogger
.debug("executeQuery() receives response: \(resultsString, privacy: .private).")


// Not doing error decoding here
guard results.errors.isEmpty else {
throw DataConnectError
.operationExecutionFailed(messages: createErrorJson(errors: results.errors))
throw DataConnectError.operationExecutionFailed(
messages: createErrorJson(errors: results.errors),
response: OperationFailureResponseImpl(
jsonData: resultsString,
errorInfoList: []
)
)
}

if let decodedResults = try codec.decode(result: results.data, asType: resultType) {
Expand All @@ -163,7 +169,13 @@ actor GrpcClient: CustomStringConvertible {
// In future, set this as error in OperationResult
DataConnectLogger
.debug("executeQuery() response: \(resultsString, privacy: .private) decode failed.")
throw DataConnectError.decodeFailed
throw DataConnectError.operationExecutionFailed(
messages: "decode failed",
response: OperationFailureResponseImpl(
jsonData: resultsString,
errorInfoList: []
)
)
}
} catch {
DataConnectLogger.error(
Expand Down Expand Up @@ -201,16 +213,27 @@ actor GrpcClient: CustomStringConvertible {
.debug("executeMutation() receives response: \(resultsString, privacy: .private).")

guard results.errors.isEmpty else {
throw DataConnectError
.operationExecutionFailed(messages: createErrorJson(errors: results.errors))
throw DataConnectError.operationExecutionFailed(
messages: createErrorJson(errors: results.errors),
response: OperationFailureResponseImpl(
jsonData: resultsString,
errorInfoList: []
)
)
}

if let decodedResults = try codec.decode(result: results.data, asType: resultType) {
return OperationResult(data: decodedResults)
} else {
DataConnectLogger
.debug("executeMutation() response: \(resultsString, privacy: .private) decode failed.")
throw DataConnectError.decodeFailed
throw DataConnectError.operationExecutionFailed(
messages: "decode failed",
response: OperationFailureResponseImpl(
jsonData: resultsString,
errorInfoList: []
)
)
}
} catch {
DataConnectLogger.error(
Expand Down
Loading