Skip to content

Commit c7fe40d

Browse files
authored
Conform Swiftly's Error type to CustomStringConvertible (#203)
`swift-argument-parser` will use an Error's description when printing the error. This patch conforms Swiftly's Error type to CustomStringConvertible, which will show the actual message in stdout instead of the object's description of `Error(message: "...")` Issue: #201
1 parent 8aa8d18 commit c7fe40d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Sources/SwiftlyCore/Error.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import Foundation
22

3-
public struct Error: LocalizedError {
3+
public struct Error: LocalizedError, CustomStringConvertible {
44
public let message: String
55

66
public init(message: String) {
77
self.message = message
88
}
99

10-
public var errorDescription: String? { self.message }
10+
public var errorDescription: String { self.message }
11+
public var description: String { self.message }
1112
}

Tools/build-swiftly-release/BuildSwiftlyRelease.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ public struct SwiftRelease: Codable {
1212
}
1313

1414
// These functions are cloned and adapted from SwiftlyCore until we can do better bootstrapping
15-
public struct Error: LocalizedError {
15+
public struct Error: LocalizedError, CustomStringConvertible {
1616
public let message: String
1717

1818
public init(message: String) {
1919
self.message = message
2020
}
2121

22-
public var errorDescription: String? { self.message }
22+
public var errorDescription: String { self.message }
23+
public var description: String { self.message }
2324
}
2425

2526
public func runProgramEnv(_ args: String..., quiet: Bool = false, env: [String: String]?) throws {

0 commit comments

Comments
 (0)