Skip to content

Commit dbab63a

Browse files
committed
docs: Update README
1 parent ff0a2d1 commit dbab63a

File tree

9 files changed

+382
-656
lines changed

9 files changed

+382
-656
lines changed

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ let package = Package(
2525
.target(name: "Nexus", dependencies: ["AstrojectCore"], plugins: [.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLint")]),
2626
.target(name: "Singularity", dependencies: ["AstrojectCore"], plugins: [.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLint")]),
2727

28-
.testTarget(name: "CoreTests", dependencies: ["AstrojectCore"]),
29-
.testTarget(name: "NexusTests", dependencies: ["Nexus"]),
30-
.testTarget(name: "SingularityTests", dependencies: ["Singularity"]),
28+
.testTarget(name: "CoreTests", dependencies: ["AstrojectCore"], plugins: [.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLint")]),
29+
.testTarget(name: "NexusTests", dependencies: ["Nexus"], plugins: [.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLint")]),
30+
.testTarget(name: "SingularityTests", dependencies: ["Singularity"], plugins: [.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLint")]),
3131
]
3232
)

README.md

Lines changed: 342 additions & 211 deletions
Large diffs are not rendered by default.

Sources/AstrojectCore/AstrojectError.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public enum AstrojectError: LocalizedError {
1717
/// A dependency is requested but no corresponding registration is found in the container.
1818
///
1919
/// This case occurs when attempting to resolve a dependency that has not been registered.
20-
case noRegistrationFound
20+
case noRegistrationFound(type: String, name: String? = nil)
2121

2222
/// A circular dependency is detected during the resolution process.
2323
///
@@ -47,8 +47,12 @@ public enum AstrojectError: LocalizedError {
4747
} else {
4848
return "A registration for type '\(type)' already exists."
4949
}
50-
case .noRegistrationFound:
51-
return "No registration found for the requested dependency."
50+
case .noRegistrationFound(let type, let name):
51+
if let name {
52+
return "No registration found for dependency of '\(type)' with name '\(name)'."
53+
} else {
54+
return "No registration found for dependency of '\(type)'."
55+
}
5256
case .circularDependencyDetected(let type, let name):
5357
if let name = name {
5458
return "A circular dependency was detected while resolving type '\(type)' with name '\(name)'."
@@ -109,12 +113,13 @@ extension AstrojectError: Equatable {
109113
public static func == (lhs: AstrojectError, rhs: AstrojectError) -> Bool {
110114
switch (lhs, rhs) {
111115
case (.alreadyRegistered(let lhsType, let lhsName), .alreadyRegistered(let rhsType, let rhsName)),
116+
(.noRegistrationFound(let lhsType, let lhsName),
117+
.noRegistrationFound(let rhsType, let rhsName)),
112118
(.circularDependencyDetected(let lhsType, let lhsName),
113119
.circularDependencyDetected(let rhsType, let rhsName)):
114120
// Compare the associated types and names for alreadyRegistered and circularDependencyDetected errors.
115121
return lhsType == rhsType && lhsName == rhsName
116-
case (.noRegistrationFound, .noRegistrationFound),
117-
(.invalidInstance, .invalidInstance):
122+
case (.invalidInstance, .invalidInstance):
118123
// noRegistrationFound and invalidInstance errors are equal if they are the same case.
119124
return true
120125
case (.underlyingError(let lhsError), .underlyingError(let rhsError)):

Sources/AstrojectCore/Container.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ extension Container {
430430
}
431431
// If no registration is found for the given key, throw an error.
432432
guard let registration else {
433-
throw AstrojectError.noRegistrationFound
433+
throw AstrojectError.noRegistrationFound(type: "\(productType)", name: name)
434434
}
435435

436436
// Return the found registration.
@@ -460,7 +460,12 @@ extension Container {
460460

461461
// If no registration is found, throw an error indicating that.
462462
guard let registration else {
463-
throw AstrojectError.noRegistrationFound
463+
let argumentType = type(of: argument)
464+
let spacing = name == nil ? "" : " "
465+
let nameAndArgument = name ?? "" + "\(spacing)argument of type: \(argumentType)"
466+
throw AstrojectError.noRegistrationFound(
467+
type: "\(productType)",
468+
name: nameAndArgument)
464469
}
465470

466471
// Return the found registration.

0 commit comments

Comments
 (0)