From 8b202e9a6fbffa39a787fabb4444b81c5a4d1804 Mon Sep 17 00:00:00 2001 From: Andrew Roan Date: Fri, 27 Feb 2026 16:34:45 -0600 Subject: [PATCH 1/3] Add static errorDescription requirement to FetchableUnmanagedModel fix-incorrect-error-descriptions --- Sources/CoreDataRepository/FetchableUnmanagedModel.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/CoreDataRepository/FetchableUnmanagedModel.swift b/Sources/CoreDataRepository/FetchableUnmanagedModel.swift index a177eb9..c60929b 100644 --- a/Sources/CoreDataRepository/FetchableUnmanagedModel.swift +++ b/Sources/CoreDataRepository/FetchableUnmanagedModel.swift @@ -70,6 +70,9 @@ public protocol FetchableUnmanagedModel: Sendable { /// A description of the context from where an error is thrown var errorDescription: String { get } + + /// A description of the context from where an error is thrown but there is no instance `self` to use + static var errorDescription: String { get } } extension FetchableUnmanagedModel { @@ -85,4 +88,9 @@ extension FetchableUnmanagedModel { public var errorDescription: String { "\(Self.self)" } + + @inlinable + public static var errorDescription: String { + "\(Self.self)" + } } From 20f7c84078e2199f7ff22e30ea1ec6314fd8e6b0 Mon Sep 17 00:00:00 2001 From: Andrew Roan Date: Fri, 27 Feb 2026 16:35:21 -0600 Subject: [PATCH 2/3] Use errorDescription instead of Self.self where possible fix-incorrect-error-descriptions --- Sources/CoreDataRepository/IdentifiedUnmanagedModel.swift | 8 ++++++-- Sources/CoreDataRepository/ReadableUnmanagedModel.swift | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Sources/CoreDataRepository/IdentifiedUnmanagedModel.swift b/Sources/CoreDataRepository/IdentifiedUnmanagedModel.swift index 9899b71..d76607b 100644 --- a/Sources/CoreDataRepository/IdentifiedUnmanagedModel.swift +++ b/Sources/CoreDataRepository/IdentifiedUnmanagedModel.swift @@ -32,11 +32,15 @@ extension IdentifiedUnmanagedModel { let fetchResult = try context.fetch(request) guard let managed = fetchResult.first, fetchResult.count == 1 else { throw CoreDataError - .noMatchFoundWhenReadingItem(description: "\(Self.self) -- id: \(errorDescription(for: id))") + .noMatchFoundWhenReadingItem( + description: "\(Self.errorDescription) -- id: \(errorDescription(for: id))" + ) } guard !managed.isDeleted else { throw CoreDataError - .fetchedObjectIsFlaggedAsDeleted(description: "\(Self.self) -- id: \(errorDescription(for: id))") + .fetchedObjectIsFlaggedAsDeleted( + description: "\(Self.errorDescription) -- id: \(errorDescription(for: id))" + ) } return managed } diff --git a/Sources/CoreDataRepository/ReadableUnmanagedModel.swift b/Sources/CoreDataRepository/ReadableUnmanagedModel.swift index 2a5eb0a..25e7ae0 100644 --- a/Sources/CoreDataRepository/ReadableUnmanagedModel.swift +++ b/Sources/CoreDataRepository/ReadableUnmanagedModel.swift @@ -80,7 +80,7 @@ extension ReadableUnmanagedModel where Self: ManagedIdReferencable { @inlinable public func readManaged(from context: NSManagedObjectContext) throws -> ManagedModel { guard let managedId else { - throw CoreDataError.noObjectIdOnItem(description: "\(Self.self)") + throw CoreDataError.noObjectIdOnItem(description: errorDescription) } return try context.notDeletedObject(for: managedId).asManagedModel() } @@ -90,7 +90,7 @@ extension ReadableUnmanagedModel where Self: ManagedIdUrlReferencable { @inlinable public func readManaged(from context: NSManagedObjectContext) throws -> ManagedModel { guard let managedIdUrl else { - throw CoreDataError.noUrlOnItemToMapToObjectId(description: "\(Self.self)") + throw CoreDataError.noUrlOnItemToMapToObjectId(description: errorDescription) } let managedId = try context.objectId(from: managedIdUrl).get() return try context.notDeletedObject(for: managedId).asManagedModel() From b91ae75b7cf4591832ce06cc7452f4506a28d6e6 Mon Sep 17 00:00:00 2001 From: Andrew Roan Date: Fri, 27 Feb 2026 17:23:33 -0600 Subject: [PATCH 3/3] Add default conformance for unamangeId error description when UnmanagedId conforms to CustomStringConvertible fix-incorrect-error-descriptions --- Sources/CoreDataRepository/IdentifiedUnmanagedModel.swift | 6 ++++++ .../Internal/ModelsWithIntId/IdentifiableModel_Int.swift | 4 ---- .../Internal/ModelsWithUuidId/IdentifiableModel_Uuid.swift | 4 ---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Sources/CoreDataRepository/IdentifiedUnmanagedModel.swift b/Sources/CoreDataRepository/IdentifiedUnmanagedModel.swift index d76607b..36e3f30 100644 --- a/Sources/CoreDataRepository/IdentifiedUnmanagedModel.swift +++ b/Sources/CoreDataRepository/IdentifiedUnmanagedModel.swift @@ -45,3 +45,9 @@ extension IdentifiedUnmanagedModel { return managed } } + +extension IdentifiedUnmanagedModel where UnmanagedId: CustomStringConvertible { + public static func errorDescription(for unmanagedId: UnmanagedId) -> String { + unmanagedId.description + } +} diff --git a/Sources/Internal/ModelsWithIntId/IdentifiableModel_Int.swift b/Sources/Internal/ModelsWithIntId/IdentifiableModel_Int.swift index 15cd66f..bf0a287 100644 --- a/Sources/Internal/ModelsWithIntId/IdentifiableModel_Int.swift +++ b/Sources/Internal/ModelsWithIntId/IdentifiableModel_Int.swift @@ -105,10 +105,6 @@ extension IdentifiableModel_IntId: IdentifiedUnmanagedModel { } package nonisolated(unsafe) static let unmanagedIdExpression = NSExpression(forKeyPath: \ManagedModel_IntId.id) - - package static func errorDescription(for unmanagedId: Int) -> String { - unmanagedId.description - } } extension IdentifiableModel_IntId: WritableUnmanagedModel { diff --git a/Sources/Internal/ModelsWithUuidId/IdentifiableModel_Uuid.swift b/Sources/Internal/ModelsWithUuidId/IdentifiableModel_Uuid.swift index 6bc34fd..71f805f 100644 --- a/Sources/Internal/ModelsWithUuidId/IdentifiableModel_Uuid.swift +++ b/Sources/Internal/ModelsWithUuidId/IdentifiableModel_Uuid.swift @@ -105,10 +105,6 @@ extension IdentifiableModel_UuidId: IdentifiedUnmanagedModel { } package nonisolated(unsafe) static let unmanagedIdExpression = NSExpression(forKeyPath: \ManagedModel_UuidId.id) - - package static func errorDescription(for unmanagedId: UUID) -> String { - unmanagedId.uuidString - } } extension IdentifiableModel_UuidId: WritableUnmanagedModel {