Skip to content

Commit 1b7d794

Browse files
author
Brandon Sneed
committed
Split out error codes for not-installed vs. not-initialized.
1 parent 6c9592e commit 1b7d794

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

ModuloKit/ErrorCode.swift

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ import Foundation
1515

1616
public enum ErrorCode: Int {
1717
case success = 0
18-
case unknownError = 1
19-
case commandError = 2
20-
case specNotFound = 3
21-
case specNotWritable = 4
22-
case noSCMFoundOrInitialized = 5
23-
case alreadyInitialized = 6
24-
case notInitialized = 7
25-
case noMatchingDependencies = 8
26-
case dependencyAlreadyExists = 9
27-
case dependencyUnclean = 10
28-
case dependencyUnknown = 11
18+
case unknownError
19+
case commandError
20+
case specNotFound
21+
case specNotWritable
22+
case scmNotFound
23+
case scmNotInitialized
24+
case alreadyInitialized
25+
case notInitialized
26+
case noMatchingDependencies
27+
case dependencyAlreadyExists
28+
case dependencyUnclean
29+
case dependencyUnknown
2930

3031
var description: String {
3132
var result: String = ""
@@ -40,8 +41,10 @@ public enum ErrorCode: Int {
4041
result = ".modulo file not found."
4142
case .specNotWritable:
4243
result = ".modulo cannot be written to, check permissions."
43-
case .noSCMFoundOrInitialized:
44-
result = "No supported SCM was found to be initialized."
44+
case .scmNotFound:
45+
result = "No supported SCM was found."
46+
case .scmNotInitialized:
47+
result = "An SCM has not been initialized in this directory."
4548
case .alreadyInitialized:
4649
result = "Modulo has already been initialized."
4750
case .notInitialized:

ModuloKit/SCM/SCM.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,20 @@ public func currentSCM() -> SCM {
259259
let installed = scm.isInstalled
260260
let initialized = scm.isInitialized
261261

262+
if !installed {
263+
exit(.scmNotFound)
264+
}
265+
266+
if !initialized {
267+
exit(.scmNotInitialized)
268+
}
269+
262270
if installed && initialized {
263271
result = scm
264272
break
265273
}
266274
}
267275

268-
if result == nil {
269-
exit(.noSCMFoundOrInitialized)
270-
}
271-
272276
return result!
273277
}
274278

0 commit comments

Comments
 (0)