From 9fa58d4959b5892a352d6539a9e9c8c2bfb84de9 Mon Sep 17 00:00:00 2001
From: Dan Federman <dfed@me.com>
Date: Wed, 10 Jan 2024 14:00:18 -0700
Subject: [PATCH] Try using 'localizedDescription' instead of 'description' on
 errors

---
 Sources/SafeDICore/Errors/FixableInjectableError.swift      | 2 ++
 Sources/SafeDICore/Errors/FixableInstantiableError.swift    | 2 ++
 Sources/SafeDICore/Generators/DependencyTreeGenerator.swift | 2 ++
 Sources/SafeDICore/Generators/ScopeGenerator.swift          | 2 ++
 Sources/SafeDICore/Models/Scope.swift                       | 2 ++
 Sources/SafeDIMacros/Macros/InjectableMacro.swift           | 2 ++
 Sources/SafeDIMacros/Macros/InstantiableMacro.swift         | 2 ++
 Sources/SafeDITool/SafeDITool.swift                         | 2 ++
 Tests/SafeDIToolTests/SafeDIToolTests.swift                 | 2 +-
 9 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/Sources/SafeDICore/Errors/FixableInjectableError.swift b/Sources/SafeDICore/Errors/FixableInjectableError.swift
index feec2ec3..88e40935 100644
--- a/Sources/SafeDICore/Errors/FixableInjectableError.swift
+++ b/Sources/SafeDICore/Errors/FixableInjectableError.swift
@@ -30,6 +30,8 @@ public enum FixableInjectableError: DiagnosticError {
         }
     }
 
+    public var localizedDescription: String { description }
+
     public var diagnostic: DiagnosticMessage {
         InjectableDiagnosticMessage(error: self)
     }
diff --git a/Sources/SafeDICore/Errors/FixableInstantiableError.swift b/Sources/SafeDICore/Errors/FixableInstantiableError.swift
index 5f87c7fb..1ec899af 100644
--- a/Sources/SafeDICore/Errors/FixableInstantiableError.swift
+++ b/Sources/SafeDICore/Errors/FixableInstantiableError.swift
@@ -58,6 +58,8 @@ public enum FixableInstantiableError: DiagnosticError {
         }
     }
 
+    public var localizedDescription: String { description }
+
     public var diagnostic: DiagnosticMessage {
         InstantiableDiagnosticMessage(error: self)
     }
diff --git a/Sources/SafeDICore/Generators/DependencyTreeGenerator.swift b/Sources/SafeDICore/Generators/DependencyTreeGenerator.swift
index 5f6aabfd..b3c804e7 100644
--- a/Sources/SafeDICore/Generators/DependencyTreeGenerator.swift
+++ b/Sources/SafeDICore/Generators/DependencyTreeGenerator.swift
@@ -93,6 +93,8 @@ public final class DependencyTreeGenerator {
             }
         }
 
+        var localizedDescription: String { description }
+
         struct UnfulfillableProperty: Hashable, Comparable {
             static func < (lhs: DependencyTreeGenerator.DependencyTreeGeneratorError.UnfulfillableProperty, rhs: DependencyTreeGenerator.DependencyTreeGeneratorError.UnfulfillableProperty) -> Bool {
                 lhs.property < rhs.property
diff --git a/Sources/SafeDICore/Generators/ScopeGenerator.swift b/Sources/SafeDICore/Generators/ScopeGenerator.swift
index 96da7999..608034be 100644
--- a/Sources/SafeDICore/Generators/ScopeGenerator.swift
+++ b/Sources/SafeDICore/Generators/ScopeGenerator.swift
@@ -285,6 +285,8 @@ actor ScopeGenerator {
                 "Property `\(property.asSource)` on \(instantiable.concreteInstantiableType.asSource) incorrectly configured. Property should instead be of type `\(Dependency.forwardingInstantiatorType)<\(expectedType.asSource), \(property.typeDescription.asInstantiatedType.asSource)>`. First generic argument must match type of @\(Dependency.Source.forwarded.rawValue) property."
             }
         }
+
+        var localizedDescription: String { description }
     }
 }
 
diff --git a/Sources/SafeDICore/Models/Scope.swift b/Sources/SafeDICore/Models/Scope.swift
index fe245394..ae411645 100644
--- a/Sources/SafeDICore/Models/Scope.swift
+++ b/Sources/SafeDICore/Models/Scope.swift
@@ -133,5 +133,7 @@ final class Scope {
                 """
             }
         }
+
+        var localizedDescription: String { description }
     }
 }
diff --git a/Sources/SafeDIMacros/Macros/InjectableMacro.swift b/Sources/SafeDIMacros/Macros/InjectableMacro.swift
index 81ef9480..bbfca264 100644
--- a/Sources/SafeDIMacros/Macros/InjectableMacro.swift
+++ b/Sources/SafeDIMacros/Macros/InjectableMacro.swift
@@ -121,5 +121,7 @@ public struct InjectableMacro: PeerMacro {
                 "The argument `ofType` must be a type literal"
             }
         }
+
+        var localizedDescription: String { description }
     }
 }
diff --git a/Sources/SafeDIMacros/Macros/InstantiableMacro.swift b/Sources/SafeDIMacros/Macros/InstantiableMacro.swift
index 21eeddf2..2b24ee84 100644
--- a/Sources/SafeDIMacros/Macros/InstantiableMacro.swift
+++ b/Sources/SafeDIMacros/Macros/InstantiableMacro.swift
@@ -209,5 +209,7 @@ public struct InstantiableMacro: MemberMacro {
                 "@\(InstantiableVisitor.macroName)-decorated extension must have a single `instantiate()` method"
             }
         }
+
+        var localizedDescription: String { description }
     }
 }
diff --git a/Sources/SafeDITool/SafeDITool.swift b/Sources/SafeDITool/SafeDITool.swift
index cb56ea6a..3aad3f1c 100644
--- a/Sources/SafeDITool/SafeDITool.swift
+++ b/Sources/SafeDITool/SafeDITool.swift
@@ -233,6 +233,8 @@ struct SafeDITool: AsyncParsableCommand {
                 "@\(InstantiableVisitor.macroName)-decorated types and extensions must have globally unique type names and fulfill globally unqiue types. Found multiple types or extensions fulfilling `\(duplicateInstantiable)`"
             }
         }
+
+        var localizedDescription: String { description }
     }
 }
 
diff --git a/Tests/SafeDIToolTests/SafeDIToolTests.swift b/Tests/SafeDIToolTests/SafeDIToolTests.swift
index d1bc826a..4ab90141 100644
--- a/Tests/SafeDIToolTests/SafeDIToolTests.swift
+++ b/Tests/SafeDIToolTests/SafeDIToolTests.swift
@@ -2737,7 +2737,7 @@ final class SafeDIToolTests: XCTestCase {
             _ = try await block()
         } catch {
             didThrow = true
-            XCTAssertEqual((error as CustomStringConvertible).description, errorDescription, line: line)
+            XCTAssertEqual(error.localizedDescription, errorDescription, line: line)
         }
         XCTAssertTrue(didThrow, "Did not throw error!", line: line)
     }