Skip to content

Commit

Permalink
Conform Swiftly's Error type to CustomStringConvertible (#203)
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
plemarquand authored Jan 17, 2025
1 parent 8aa8d18 commit c7fe40d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions Sources/SwiftlyCore/Error.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import Foundation

public struct Error: LocalizedError {
public struct Error: LocalizedError, CustomStringConvertible {
public let message: String

public init(message: String) {
self.message = message
}

public var errorDescription: String? { self.message }
public var errorDescription: String { self.message }
public var description: String { self.message }
}
5 changes: 3 additions & 2 deletions Tools/build-swiftly-release/BuildSwiftlyRelease.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ public struct SwiftRelease: Codable {
}

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

public init(message: String) {
self.message = message
}

public var errorDescription: String? { self.message }
public var errorDescription: String { self.message }
public var description: String { self.message }
}

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

0 comments on commit c7fe40d

Please sign in to comment.