Skip to content

Commit 2ef789c

Browse files
committed
Merge branch 'main' into implement-protocols
2 parents 96d37c4 + 6a75aeb commit 2ef789c

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"javaPackage": "com.example.swift"
2+
"javaPackage": "com.example.swift",
3+
"logLevel": "trace"
34
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"javaPackage": "com.example.swift",
33
"mode": "jni",
4-
"logLevel": ["debug"],
54
"enableJavaCallbacks": true
5+
"logLevel": "debug"
66
}

Sources/SwiftJavaConfigurationShared/Configuration.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ public func readConfiguration(string: String, configPath: URL?, file: String = #
193193
decoder.allowsJSON5 = true
194194
return try decoder.decode(Configuration.self, from: configData)
195195
} catch {
196-
throw ConfigurationError(message: "Failed to parse SwiftJava configuration at '\(configPath.map({ $0.absoluteURL.description }) ?? "<no-path>")'! \(#fileID):\(#line)", error: error,
196+
throw ConfigurationError(
197+
message: "Failed to parse SwiftJava configuration at '\(configPath.map({ $0.absoluteURL.description }) ?? "<no-path>")'! \(#fileID):\(#line)",
198+
error: error,
199+
text: string,
197200
file: file, line: line)
198201
}
199202
}
@@ -286,31 +289,37 @@ extension Configuration {
286289
public struct ConfigurationError: Error {
287290
let message: String
288291
let error: any Error
292+
let text: String?
289293

290294
let file: String
291295
let line: UInt
292296

293-
init(message: String, error: any Error, file: String = #fileID, line: UInt = #line) {
297+
init(message: String, error: any Error, text: String?, file: String = #fileID, line: UInt = #line) {
294298
self.message = message
295299
self.error = error
300+
self.text = text
296301
self.file = file
297302
self.line = line
298303
}
299304
}
300305

301-
public enum LogLevel: String, Codable, Hashable {
306+
public enum LogLevel: String, ExpressibleByStringLiteral, Codable, Hashable {
302307
case trace = "trace"
303308
case debug = "debug"
304309
case info = "info"
305310
case notice = "notice"
306311
case warning = "warning"
307312
case error = "error"
308313
case critical = "critical"
314+
315+
public init(stringLiteral value: String) {
316+
self = LogLevel(rawValue: value) ?? .info
317+
}
309318
}
310319

311320
extension LogLevel {
312321
public init(from decoder: any Decoder) throws {
313-
var container = try decoder.unkeyedContainer()
322+
var container = try decoder.singleValueContainer()
314323
let string = try container.decode(String.self)
315324
switch string {
316325
case "trace": self = .trace

0 commit comments

Comments
 (0)