mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2025-01-06 04:35:43 +03:00
Throw error instead of fatalError
This commit is contained in:
parent
70cb2df5f7
commit
c432337ef7
@ -19,9 +19,6 @@ public struct TargetReference: Hashable {
|
||||
extension TargetReference {
|
||||
public init(string: String) throws {
|
||||
let paths = string.split(separator: "/")
|
||||
guard paths.count <= 2 && !paths.isEmpty else {
|
||||
throw SpecParsingError.invalidTargetReference(string)
|
||||
}
|
||||
switch paths.count {
|
||||
case 2:
|
||||
location = .project(String(paths[0]))
|
||||
@ -29,7 +26,8 @@ extension TargetReference {
|
||||
case 1:
|
||||
location = .local
|
||||
name = String(paths[0])
|
||||
default: fatalError("unreachable")
|
||||
default:
|
||||
throw SpecParsingError.invalidTargetReference(string)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ public class SchemeGenerator {
|
||||
switch buildTarget.target.location {
|
||||
case .project(let project):
|
||||
guard let projectReference = self.project.getProjectReference(project) else {
|
||||
fatalError("Unable to find project reference named \"\(project)\" in project.yml")
|
||||
throw SchemeGenerationError.missingProject(project)
|
||||
}
|
||||
pbxProj = try XcodeProj(pathString: projectReference.path).pbxproj
|
||||
projectFilePath = projectReference.path
|
||||
@ -99,7 +99,7 @@ public class SchemeGenerator {
|
||||
}
|
||||
|
||||
guard let pbxTarget = pbxProj.targets(named: buildTarget.target.name).first else {
|
||||
fatalError("Unable to find target named \"\(buildTarget.target)\" in \"PBXProj.targets\"")
|
||||
throw SchemeGenerationError.missingTarget(buildTarget, projectPath: projectFilePath)
|
||||
}
|
||||
|
||||
let buildableName: String
|
||||
@ -111,7 +111,7 @@ public class SchemeGenerator {
|
||||
guard let _buildableName =
|
||||
project.getTarget(buildTarget.target.name)?.filename ??
|
||||
project.getAggregateTarget(buildTarget.target.name)?.name else {
|
||||
fatalError("Unable to determinate \"buildableName\" for build target: \(buildTarget.target)")
|
||||
throw SchemeGenerationError.unresolvableBuildableName(buildTarget)
|
||||
}
|
||||
buildableName = _buildableName
|
||||
}
|
||||
@ -241,6 +241,24 @@ public class SchemeGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
enum SchemeGenerationError: Error, CustomStringConvertible {
|
||||
|
||||
case unresolvableBuildableName(Scheme.BuildTarget)
|
||||
case missingTarget(Scheme.BuildTarget, projectPath: String)
|
||||
case missingProject(String)
|
||||
|
||||
var description: String {
|
||||
switch self {
|
||||
case .unresolvableBuildableName(let buildTarget):
|
||||
return "Unable to determinate \"buildableName\" for build target: \(buildTarget.target)"
|
||||
case .missingTarget(let buildTarget, let projectPath):
|
||||
return "Unable to find target named \"\(buildTarget.target)\" in \"\(projectPath)\""
|
||||
case .missingProject(let project):
|
||||
return "Unable to find project reference named \"\(project)\" in project.yml"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Scheme {
|
||||
public init(name: String, target: Target, targetScheme: TargetScheme, debugConfig: String, releaseConfig: String) {
|
||||
self.init(
|
||||
|
Loading…
Reference in New Issue
Block a user