Skip to content

Commit 255d8dd

Browse files
Unnest PathSegment definition
1 parent 2a52e58 commit 255d8dd

File tree

3 files changed

+44
-34
lines changed

3 files changed

+44
-34
lines changed

Sources/DataConnectError.swift

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -248,38 +248,5 @@ public struct OperationFailureResponse: Sendable {
248248
public let message: String
249249
// The path to the field to which this error applies.
250250
public let path: [PathSegment]
251-
252-
public enum PathSegment: Codable, Equatable, Sendable {
253-
case field(String)
254-
case listIndex(Int)
255-
}
256-
}
257-
}
258-
259-
// Information about an error provided by the backend in its response.
260-
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
261-
262-
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
263-
public extension OperationFailureResponse.ErrorInfo.PathSegment {
264-
init(from decoder: any Decoder) throws {
265-
let container = try decoder.singleValueContainer()
266-
267-
do {
268-
let field = try container.decode(String.self)
269-
self = .field(field)
270-
} catch {
271-
let index = try container.decode(Int.self)
272-
self = .listIndex(index)
273-
}
274-
}
275-
276-
func encode(to encoder: any Encoder) throws {
277-
var container = encoder.singleValueContainer()
278-
switch self {
279-
case let .field(fieldVal):
280-
try container.encode(fieldVal)
281-
case let .listIndex(indexVal):
282-
try container.encode(indexVal)
283-
}
284251
}
285252
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
public enum PathSegment: Codable, Equatable, Sendable {
16+
case field(String)
17+
case listIndex(Int)
18+
}
19+
20+
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
21+
public extension PathSegment {
22+
init(from decoder: any Decoder) throws {
23+
let container = try decoder.singleValueContainer()
24+
25+
do {
26+
let field = try container.decode(String.self)
27+
self = .field(field)
28+
} catch {
29+
let index = try container.decode(Int.self)
30+
self = .listIndex(index)
31+
}
32+
}
33+
34+
func encode(to encoder: any Encoder) throws {
35+
var container = encoder.singleValueContainer()
36+
switch self {
37+
case let .field(fieldVal):
38+
try container.encode(fieldVal)
39+
case let .listIndex(indexVal):
40+
try container.encode(indexVal)
41+
}
42+
}
43+
}

Tests/Integration/PartialErrorsTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ final class PartialErrorTests: IntegrationTestBase {
4848
throw dcError
4949
}
5050

51-
let foo1Path = [OperationFailureResponse.ErrorInfo.PathSegment.field("person2")]
51+
let foo1Path = [PathSegment.field("person2")]
5252
let error = response.errors.first(where: { $0.path == foo1Path })
5353
XCTAssertNotNil(error)
5454

0 commit comments

Comments
 (0)