Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try using 'localizedDescription' instead of 'description' on errors
Browse files Browse the repository at this point in the history
dfed committed Jan 10, 2024
1 parent 9cd3526 commit 29dd651
Showing 9 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Sources/SafeDICore/Errors/FixableInjectableError.swift
Original file line number Diff line number Diff line change
@@ -30,6 +30,8 @@ public enum FixableInjectableError: DiagnosticError {
}
}

public var localizedDescription: String { description }

public var diagnostic: DiagnosticMessage {
InjectableDiagnosticMessage(error: self)
}
2 changes: 2 additions & 0 deletions Sources/SafeDICore/Errors/FixableInstantiableError.swift
Original file line number Diff line number Diff line change
@@ -58,6 +58,8 @@ public enum FixableInstantiableError: DiagnosticError {
}
}

public var localizedDescription: String { description }

public var diagnostic: DiagnosticMessage {
InstantiableDiagnosticMessage(error: self)
}
2 changes: 2 additions & 0 deletions Sources/SafeDICore/Generators/DependencyTreeGenerator.swift
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions Sources/SafeDICore/Generators/ScopeGenerator.swift
Original file line number Diff line number Diff line change
@@ -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 }
}
}

2 changes: 2 additions & 0 deletions Sources/SafeDICore/Models/Scope.swift
Original file line number Diff line number Diff line change
@@ -133,5 +133,7 @@ final class Scope {
"""
}
}

var localizedDescription: String { description }
}
}
2 changes: 2 additions & 0 deletions Sources/SafeDIMacros/Macros/InjectableMacro.swift
Original file line number Diff line number Diff line change
@@ -121,5 +121,7 @@ public struct InjectableMacro: PeerMacro {
"The argument `ofType` must be a type literal"
}
}

var localizedDescription: String { description }
}
}
2 changes: 2 additions & 0 deletions Sources/SafeDIMacros/Macros/InstantiableMacro.swift
Original file line number Diff line number Diff line change
@@ -209,5 +209,7 @@ public struct InstantiableMacro: MemberMacro {
"@\(InstantiableVisitor.macroName)-decorated extension must have a single `instantiate()` method"
}
}

var localizedDescription: String { description }
}
}
4 changes: 2 additions & 2 deletions Sources/SafeDITool/SafeDITool.swift
Original file line number Diff line number Diff line change
@@ -221,11 +221,11 @@ struct SafeDITool: AsyncParsableCommand {
let nestedInstantiableDecoratedTypeDescriptions: [TypeDescription]
}

private enum CollectInstantiablesError: Error, CustomStringConvertible {
private enum CollectInstantiablesError: Error {
case foundNestedInstantiables([String])
case foundDuplicateInstantiable(String)

var description: String {
var localizedDescription: String {
switch self {
case let .foundNestedInstantiables(nestedInstantiables):
"@\(InstantiableVisitor.macroName) types must be top-level declarations. Found the following nested @\(InstantiableVisitor.macroName) types: \(nestedInstantiables.joined(separator: ", "))"
2 changes: 1 addition & 1 deletion Tests/SafeDIToolTests/SafeDIToolTests.swift
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 29dd651

Please sign in to comment.