Skip to content

Commit e7f7657

Browse files
committed
Fix ExpressibleByArgument conformance on LogLevel
The initializer is failable, not throwing, and there is a default conformance provided via the integer literal that was not correct.
1 parent 07e0a31 commit e7f7657

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

Sources/LSPLogging/LogLevel.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,7 @@ extension LogLevel: CustomStringConvertible {
4646
}
4747

4848
extension LogLevel {
49-
enum ConversionError: Error {
50-
case unknown(value: String)
51-
case custom(String)
52-
}
53-
54-
55-
public init(argument: String) throws {
49+
public init?(argument: String) {
5650
switch argument {
5751
case "error":
5852
self = .error
@@ -66,15 +60,15 @@ extension LogLevel {
6660

6761
// Also accept a numerical log level, for parity with SOURCEKIT_LOGGING environment variable.
6862
guard let value = Int(argument) else {
69-
throw ConversionError.unknown(value: argument)
63+
return nil
7064
}
7165

7266
if let level = LogLevel(rawValue: value) {
7367
self = level
7468
} else if value > LogLevel.debug.rawValue {
7569
self = .debug
7670
} else {
77-
throw ConversionError.custom("numerical log level \(value) is out of range")
71+
return nil
7872
}
7973
}
8074
}

Sources/LSPLogging/Logging.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public final class Logger {
122122
}
123123

124124
public func setLogLevel(_ logLevel: String) {
125-
if let level = try? LogLevel(argument: logLevel) {
125+
if let level = LogLevel(argument: logLevel) {
126126
currentLevel = level
127127
}
128128
}

0 commit comments

Comments
 (0)