Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct FileCabinetDetailView: View {
)
}

@ViewBuilder @MainActor
@MainActor
private func sidebar() -> some View {
VStack {
Text(viewModel.state.fileCabinet.id.uuidString)
Expand All @@ -44,12 +44,12 @@ struct FileCabinetDetailView: View {
}
}

@ViewBuilder @MainActor
@MainActor
private func content() -> some View {
EmptyView()
}

@ViewBuilder @MainActor
@MainActor
private func detail() -> some View {
EmptyView()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct FileCabinetsView: View {
)
}

@ViewBuilder @MainActor
@MainActor
private func sidebar() -> some View {
VStack {
Button(
Expand Down Expand Up @@ -55,7 +55,7 @@ struct FileCabinetsView: View {
}
}

@ViewBuilder @MainActor
@MainActor
private func detail() -> some View {
EmptyView()
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/CoreDataRepository/CoreDataBatchError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
/// Batch operations that do not use `NSBatch*Request` are not atomic. Some operations may succeed while others fail. If
/// multiple errors are returned, it would
/// be helpful if each error is associated with the input data for the operation.
public struct CoreDataBatchError<T>: Error where T: Sendable {
public struct CoreDataBatchError<T: Sendable>: Error {
/// The input data used for the batched operation. Usually an ``UnmanagedModel`` instance or URL encoded
/// NSManagedObjectID.
public let item: T
Expand Down
83 changes: 44 additions & 39 deletions Sources/CoreDataRepository/CoreDataError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public enum CoreDataError: Error, Hashable, Sendable {
/// against the correct property.
/// If the `NSAttributeDescription` is not for the correct or expected `NSEntityDescription`, this error is
/// returned.
case propertyDoesNotMatchEntity
case propertyDoesNotMatchEntity(description: String?)

/// CoreData may return a value of a related type to what is actually needed. If casting the value CoreData returns
/// to the required type fails, this error is returned.
case fetchedObjectFailedToCastToExpectedType
case fetchedObjectFailedToCastToExpectedType(description: String?)

/// It's possible for a persisted object to be flagged as deleted but still be fetched. If that happens, this error
/// is returned.
case fetchedObjectIsFlaggedAsDeleted
case fetchedObjectIsFlaggedAsDeleted(description: String)

/// If CoreData throws a `CocoaError`, it is embedded here.
case cocoa(CocoaError)
Expand All @@ -48,40 +48,46 @@ public enum CoreDataError: Error, Hashable, Sendable {
/// If a ``ManagedIdUrlReferencable`` value is used in a transaction where it is expected to already be persisted
/// but has no `URL`
/// representing the ``NSManagedObjectID``, this error is returned.
case noUrlOnItemToMapToObjectId
case noUrlOnItemToMapToObjectId(description: String)

/// If a ``ManagedIdReferencable`` value is used in a transaction where it is expected to already be persisted but
/// has no `NSManagedObjectID`, this error is returned.
case noObjectIdOnItem
case noObjectIdOnItem(description: String)

case noMatchFoundWhenReadingItem
case noMatchFoundWhenReadingItem(description: String)

private static var noErrorDescription: String {
String(
localized: "no description",
bundle: .module,
comment: "Placeholder for when an error description is nil."
)
}

// swiftlint:disable line_length
public var localizedDescription: String {
switch self {
case .failedToGetObjectIdFromUrl:
NSLocalizedString(
"No NSManagedObjectID found that correlates to the provided URL.",
String(
localized: "No NSManagedObjectID found that correlates to the provided URL.",
bundle: .module,
comment: "Error for when an ObjectID can't be found for the provided URL."
)
case .propertyDoesNotMatchEntity:
NSLocalizedString(
"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.",
case let .propertyDoesNotMatchEntity(description: description):
String(
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)",
bundle: .module,
comment: "Error for when the developer does not provide a valid pair of NSAttributeDescription "
+ "and NSPropertyDescription (or any of their child types)."
comment: "Error for when the developer does not provide a valid pair of NSAttributeDescription and NSPropertyDescription (or any of their child types)."
)
case .fetchedObjectFailedToCastToExpectedType:
NSLocalizedString(
"The object corresponding to the provided NSManagedObjectID is an incorrect Entity or "
+ "NSManagedObject subtype. It failed to cast to the requested type.",
case let .fetchedObjectFailedToCastToExpectedType(description: description):
String(
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)",
bundle: .module,
comment: "Error for when an object is found for a given ObjectID but it is not the expected type."
)
case .fetchedObjectIsFlaggedAsDeleted:
NSLocalizedString(
"The object corresponding to the provided NSManagedObjectID is deleted and cannot be fetched.",
case let .fetchedObjectIsFlaggedAsDeleted(description: description):
String(
localized: "The object corresponding to the provided NSManagedObjectID is deleted and cannot be fetched: \(description)",
bundle: .module,
comment: "Error for when an object is fetched but is flagged as deleted and is no longer usable."
)
Expand All @@ -90,41 +96,40 @@ public enum CoreDataError: Error, Hashable, Sendable {
case let .unknown(error):
error.localizedDescription
case .noEntityNameFound:
NSLocalizedString(
"The managed object entity description does not have a name.",
String(
localized: "The managed object entity description does not have a name.",
bundle: .module,
comment: "Error for when the NSEntityDescription does not have a name."
)
case .atLeastOneAttributeDescRequired:
NSLocalizedString(
"The managed object entity has no attribute description. An attribute description is required for "
+ "aggregate operations.",
String(
localized: "The managed object entity has no attribute description. An attribute description is required for aggregate operations.",
bundle: .module,
comment: "Error for when the NSEntityDescription has no NSAttributeDescription but one is required."
)
case .noUrlOnItemToMapToObjectId:
NSLocalizedString(
"No object ID URL found on the model for an operation against an existing managed object.",
case let .noUrlOnItemToMapToObjectId(description: description):
String(
localized: "No object ID URL found on the model for an operation against an existing managed object: \(description)",
bundle: .module,
comment: "Error for performing an operation against an existing NSManagedObject but the "
+ "ManagedIdUrlReferencable instance has no managedIdUrl for looking up the NSManagedOjbectID."
comment: "Error for performing an operation against an existing NSManagedObject but the ManagedIdUrlReferencable instance has no managedIdUrl for looking up the NSManagedOjbectID."
)
case .noObjectIdOnItem:
NSLocalizedString(
"No object ID found on the model for an operation against an existing managed object.",
case let .noObjectIdOnItem(description: description):
String(
localized: "No object ID found on the model for an operation against an existing managed object: \(description)",
bundle: .module,
comment: "Error for performing an operation against an existing NSManagedObject but the "
+ "ManagedIdReferencable instance has no managedId."
comment: "Error for performing an operation against an existing NSManagedObject but the ManagedIdReferencable instance has no managedId."
)
case .noMatchFoundWhenReadingItem:
NSLocalizedString(
"No match found when attempting to read an instance from CoreData.",
case let .noMatchFoundWhenReadingItem(description: description):
String(
localized: "No match found when attempting to read an instance from CoreData: \(description)",
bundle: .module,
comment: "Error for reading an instance from CoreData but no instance was found."
)
}
}

// swiftlint:enable line_length

@usableFromInline
static func catching<T>(block: () async throws -> T) async throws(Self) -> T {
do {
Expand Down
Loading