Skip to content

Commit c39e92d

Browse files
committed
Fix error description localizations
feature/identified-description
1 parent 2a8e632 commit c39e92d

2 files changed

Lines changed: 47 additions & 39 deletions

File tree

Sources/CoreDataRepository/CoreDataError.swift

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,38 @@ public enum CoreDataError: Error, Hashable, Sendable {
5656

5757
case noMatchFoundWhenReadingItem(description: String)
5858

59+
private static var noErrorDescription: String {
60+
String(
61+
localized: "no description",
62+
bundle: .module,
63+
comment: "Placeholder for when an error description is nil."
64+
)
65+
}
66+
67+
// swiftlint:disable line_length
5968
public var localizedDescription: String {
6069
switch self {
6170
case .failedToGetObjectIdFromUrl:
62-
NSLocalizedString(
63-
"No NSManagedObjectID found that correlates to the provided URL.",
71+
String(
72+
localized: "No NSManagedObjectID found that correlates to the provided URL.",
6473
bundle: .module,
6574
comment: "Error for when an ObjectID can't be found for the provided URL."
6675
)
67-
case .propertyDoesNotMatchEntity:
68-
NSLocalizedString(
69-
"There is a mismatch between a provided NSPropertyDescrption's entity and a NSEntityDescription. "
70-
+ "When a property description is provided, it must match any related entity descriptions.",
76+
case let .propertyDoesNotMatchEntity(description: description):
77+
String(
78+
localized: "There is a mismatch between a provided NSPropertyDescrption's entity and a NSEntityDescription. When a property description is provided, it must match any related entity descriptions: \(description ?? Self.noErrorDescription)",
7179
bundle: .module,
72-
comment: "Error for when the developer does not provide a valid pair of NSAttributeDescription "
73-
+ "and NSPropertyDescription (or any of their child types)."
80+
comment: "Error for when the developer does not provide a valid pair of NSAttributeDescription and NSPropertyDescription (or any of their child types)."
7481
)
75-
case .fetchedObjectFailedToCastToExpectedType:
76-
NSLocalizedString(
77-
"The object corresponding to the provided NSManagedObjectID is an incorrect Entity or "
78-
+ "NSManagedObject subtype. It failed to cast to the requested type.",
82+
case let .fetchedObjectFailedToCastToExpectedType(description: description):
83+
String(
84+
localized: "The object corresponding to the provided NSManagedObjectID is an incorrect Entity or NSManagedObject subtype. It failed to cast to the requested type: \(description ?? Self.noErrorDescription)",
7985
bundle: .module,
8086
comment: "Error for when an object is found for a given ObjectID but it is not the expected type."
8187
)
82-
case .fetchedObjectIsFlaggedAsDeleted:
83-
NSLocalizedString(
84-
"The object corresponding to the provided NSManagedObjectID is deleted and cannot be fetched.",
88+
case let .fetchedObjectIsFlaggedAsDeleted(description: description):
89+
String(
90+
localized: "The object corresponding to the provided NSManagedObjectID is deleted and cannot be fetched: \(description)",
8591
bundle: .module,
8692
comment: "Error for when an object is fetched but is flagged as deleted and is no longer usable."
8793
)
@@ -90,41 +96,40 @@ public enum CoreDataError: Error, Hashable, Sendable {
9096
case let .unknown(error):
9197
error.localizedDescription
9298
case .noEntityNameFound:
93-
NSLocalizedString(
94-
"The managed object entity description does not have a name.",
99+
String(
100+
localized: "The managed object entity description does not have a name.",
95101
bundle: .module,
96102
comment: "Error for when the NSEntityDescription does not have a name."
97103
)
98104
case .atLeastOneAttributeDescRequired:
99-
NSLocalizedString(
100-
"The managed object entity has no attribute description. An attribute description is required for "
101-
+ "aggregate operations.",
105+
String(
106+
localized: "The managed object entity has no attribute description. An attribute description is required for aggregate operations.",
102107
bundle: .module,
103108
comment: "Error for when the NSEntityDescription has no NSAttributeDescription but one is required."
104109
)
105-
case .noUrlOnItemToMapToObjectId:
106-
NSLocalizedString(
107-
"No object ID URL found on the model for an operation against an existing managed object.",
110+
case let .noUrlOnItemToMapToObjectId(description: description):
111+
String(
112+
localized: "No object ID URL found on the model for an operation against an existing managed object: \(description)",
108113
bundle: .module,
109-
comment: "Error for performing an operation against an existing NSManagedObject but the "
110-
+ "ManagedIdUrlReferencable instance has no managedIdUrl for looking up the NSManagedOjbectID."
114+
comment: "Error for performing an operation against an existing NSManagedObject but the ManagedIdUrlReferencable instance has no managedIdUrl for looking up the NSManagedOjbectID."
111115
)
112-
case .noObjectIdOnItem:
113-
NSLocalizedString(
114-
"No object ID found on the model for an operation against an existing managed object.",
116+
case let .noObjectIdOnItem(description: description):
117+
String(
118+
localized: "No object ID found on the model for an operation against an existing managed object: \(description)",
115119
bundle: .module,
116-
comment: "Error for performing an operation against an existing NSManagedObject but the "
117-
+ "ManagedIdReferencable instance has no managedId."
120+
comment: "Error for performing an operation against an existing NSManagedObject but the ManagedIdReferencable instance has no managedId."
118121
)
119-
case .noMatchFoundWhenReadingItem:
120-
NSLocalizedString(
121-
"No match found when attempting to read an instance from CoreData.",
122+
case let .noMatchFoundWhenReadingItem(description: description):
123+
String(
124+
localized: "No match found when attempting to read an instance from CoreData: \(description)",
122125
bundle: .module,
123126
comment: "Error for reading an instance from CoreData but no instance was found."
124127
)
125128
}
126129
}
127130

131+
// swiftlint:enable line_length
132+
128133
@usableFromInline
129134
static func catching<T>(block: () async throws -> T) async throws(Self) -> T {
130135
do {

Sources/CoreDataRepository/Resources/Localizable.xcstrings

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
{
22
"sourceLanguage" : "en",
33
"strings" : {
4-
"No match found when attempting to read an instance from CoreData." : {
4+
"no description" : {
5+
"comment" : "Placeholder for when an error description is nil."
6+
},
7+
"No match found when attempting to read an instance from CoreData: %@" : {
58
"comment" : "Error for reading an instance from CoreData but no instance was found."
69
},
710
"No NSManagedObjectID found that correlates to the provided URL." : {
811
"comment" : "Error for when an ObjectID can't be found for the provided URL."
912
},
10-
"No object ID found on the model for an operation against an existing managed object." : {
13+
"No object ID found on the model for an operation against an existing managed object: %@" : {
1114
"comment" : "Error for performing an operation against an existing NSManagedObject but the ManagedIdReferencable instance has no managedId."
1215
},
13-
"No object ID URL found on the model for an operation against an existing managed object." : {
16+
"No object ID URL found on the model for an operation against an existing managed object: %@" : {
1417
"comment" : "Error for performing an operation against an existing NSManagedObject but the ManagedIdUrlReferencable instance has no managedIdUrl for looking up the NSManagedOjbectID."
1518
},
1619
"The managed object entity description does not have a name." : {
@@ -19,13 +22,13 @@
1922
"The managed object entity has no attribute description. An attribute description is required for aggregate operations." : {
2023
"comment" : "Error for when the NSEntityDescription has no NSAttributeDescription but one is required."
2124
},
22-
"The object corresponding to the provided NSManagedObjectID is an incorrect Entity or NSManagedObject subtype. It failed to cast to the requested type." : {
25+
"The object corresponding to the provided NSManagedObjectID is an incorrect Entity or NSManagedObject subtype. It failed to cast to the requested type: %@" : {
2326
"comment" : "Error for when an object is found for a given ObjectID but it is not the expected type."
2427
},
25-
"The object corresponding to the provided NSManagedObjectID is deleted and cannot be fetched." : {
28+
"The object corresponding to the provided NSManagedObjectID is deleted and cannot be fetched: %@" : {
2629
"comment" : "Error for when an object is fetched but is flagged as deleted and is no longer usable."
2730
},
28-
"There is a mismatch between a provided NSPropertyDescrption's entity and a NSEntityDescription. When a property description is provided, it must match any related entity descriptions." : {
31+
"There is a mismatch between a provided NSPropertyDescrption's entity and a NSEntityDescription. When a property description is provided, it must match any related entity descriptions: %@" : {
2932
"comment" : "Error for when the developer does not provide a valid pair of NSAttributeDescription and NSPropertyDescription (or any of their child types)."
3033
}
3134
},

0 commit comments

Comments
 (0)