Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"javaPackage": "com.example.swift"
"javaPackage": "com.example.swift",
"logLevel": "trace"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"javaPackage": "com.example.swift",
"mode": "jni",
"logLevel": ["debug"]
"logLevel": "debug"
}
17 changes: 13 additions & 4 deletions Sources/SwiftJavaConfigurationShared/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ public func readConfiguration(string: String, configPath: URL?, file: String = #
decoder.allowsJSON5 = true
return try decoder.decode(Configuration.self, from: configData)
} catch {
throw ConfigurationError(message: "Failed to parse SwiftJava configuration at '\(configPath.map({ $0.absoluteURL.description }) ?? "<no-path>")'! \(#fileID):\(#line)", error: error,
throw ConfigurationError(
message: "Failed to parse SwiftJava configuration at '\(configPath.map({ $0.absoluteURL.description }) ?? "<no-path>")'! \(#fileID):\(#line)",
error: error,
text: string,
file: file, line: line)
}
}
Expand Down Expand Up @@ -276,31 +279,37 @@ extension Configuration {
public struct ConfigurationError: Error {
let message: String
let error: any Error
let text: String?

let file: String
let line: UInt

init(message: String, error: any Error, file: String = #fileID, line: UInt = #line) {
init(message: String, error: any Error, text: String?, file: String = #fileID, line: UInt = #line) {
self.message = message
self.error = error
self.text = text
self.file = file
self.line = line
}
}

public enum LogLevel: String, Codable, Hashable {
public enum LogLevel: String, ExpressibleByStringLiteral, Codable, Hashable {
case trace = "trace"
case debug = "debug"
case info = "info"
case notice = "notice"
case warning = "warning"
case error = "error"
case critical = "critical"

public init(stringLiteral value: String) {
self = LogLevel(rawValue: value) ?? .info
}
}

extension LogLevel {
public init(from decoder: any Decoder) throws {
var container = try decoder.unkeyedContainer()
var container = try decoder.singleValueContainer()
let string = try container.decode(String.self)
switch string {
case "trace": self = .trace
Expand Down
Loading