-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
10 changed files
with
91 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,42 @@ | ||
enum DependencyError: Error, CustomStringConvertible, Equatable { | ||
case badParams(ServiceKey) | ||
case missingDependency(ServiceKey) | ||
case missingDependency(missingDependency: ServiceKey, similarDependencies: Set<ServiceKey>, dependencyCount: Int) | ||
case nilDependency(ServiceKey) | ||
|
||
var description: String { | ||
switch self { | ||
case .badParams(let serviceKey): | ||
return "Bad parameters provided for \(serviceKey.type) with name: \(serviceKey.name ?? "<no name>")" | ||
case .missingDependency(let serviceKey): | ||
return "Missing dependency for \(serviceKey.type) with name: \(serviceKey.name ?? "<no name>")" | ||
return "Bad parameters provided for \(serviceKey)" | ||
case .missingDependency(let missingDependency, let similarDependencies, let dependencyCount): | ||
return missingDeendencyDescription(missingDependency, similarDependencies, dependencyCount) | ||
case .nilDependency(let serviceKey): | ||
return "Nil dependency for \(serviceKey.type) with name: \(serviceKey.name ?? "<no name>")" | ||
return "Nil dependency for \(serviceKey)" | ||
} | ||
} | ||
|
||
private func missingDeendencyDescription(_ missingDependency: ServiceKey, | ||
_ similarDependencies: Set<ServiceKey>, | ||
_ dependencyCount: Int) -> String { | ||
let similarStrings = similarDependencies.map { "- \($0)" }.sorted() | ||
let similarJoined = similarStrings.joined(separator: "\n") | ||
let similarDescription = similarStrings.isEmpty ? "" : "\nSimilar dependencies:\n\(similarJoined)" | ||
|
||
return """ | ||
Missing dependency for \(missingDependency) | ||
Container has a total of \(dependencyCount) dependencies. | ||
""" + similarDescription | ||
} | ||
|
||
static func createMissingDependencyError( | ||
missingDependency: ServiceKey, | ||
serviceDict: ServiceDictionary<DependencyDefinition> | ||
) -> DependencyError { | ||
let similarDependencies = serviceDict.allKeys().filter { key in | ||
key.name == missingDependency.name || key.type == missingDependency.type | ||
} | ||
|
||
return .missingDependency(missingDependency: missingDependency, | ||
similarDependencies: similarDependencies, | ||
dependencyCount: serviceDict.count) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters