Skip to content

Commit a5081d9

Browse files
authored
Fix Triple formatting in error messages (#6544)
Currently `Triple` is not `CustomStringConvertible`, which leads to issues when using it in string interpolations. It uses default implementation that prints all of the triple components separately, which isn't user-readable. For example, when using `swift experimental-sdk configuration show` subcommand on a bundle that has wrong triples, an error message is printed which is badly formatted and likely does not show the root cause of the issue. rdar://107882041
1 parent fdf39fd commit a5081d9

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Sources/Basics/Triple.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import class TSCBasic.Process
1818

1919
/// Triple - Helper class for working with Destination.target values
2020
///
21-
/// Used for parsing values such as x86_64-apple-macosx10.10 into
21+
/// Used for parsing values such as `x86_64-apple-macosx10.10` into
2222
/// set of enums. For os/arch/abi based conditions in build plan.
2323
///
2424
/// @see Destination.target
@@ -318,6 +318,10 @@ extension Triple {
318318
}
319319
}
320320

321+
extension Triple: CustomStringConvertible {
322+
public var description: String { tripleString }
323+
}
324+
321325
extension Triple.Error: CustomNSError {
322326
public var errorUserInfo: [String: Any] {
323327
[NSLocalizedDescriptionKey: "\(self)"]

Tests/BasicsTests/TripleTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,9 @@ final class TripleTests: XCTestCase {
7676
XCTAssertTriple("i686-pc-windows-gnu", isApple: false, isDarwin: false)
7777
XCTAssertTriple("i686-pc-windows-cygnus", isApple: false, isDarwin: false)
7878
}
79+
80+
func testDescription() throws {
81+
let triple = try Triple("x86_64-pc-linux-gnu")
82+
XCTAssertEqual("foo \(triple) bar", "foo x86_64-pc-linux-gnu bar")
83+
}
7984
}

0 commit comments

Comments
 (0)