Skip to content

Commit 7d9cb54

Browse files
authored
Remove localizedDescription (#173)
Part of apple/swift-openapi-generator#868 Refactors `error.localizedDescription` to `"\(error)"` to prevent linking Foundation. This will change the error strings as can be seen in the tests. Alternatively, we would split the implementation by a trait `FullFoundationSupport`. Where that would use `localizedDescription`
1 parent 93e074e commit 7d9cb54

File tree

6 files changed

+8
-5
lines changed

6 files changed

+8
-5
lines changed

Sources/OpenAPIRuntime/Conversion/ErrorExtensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ struct MultiError: Swift.Error, LocalizedError, CustomStringConvertible {
124124

125125
var errorDescription: String? {
126126
if let first = errors.first {
127-
return "Multiple errors encountered, first one: \(first.localizedDescription)."
127+
return "Multiple errors encountered, first one: \(first)."
128128
} else {
129129
return "No errors"
130130
}

Sources/OpenAPIRuntime/Errors/ClientError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,6 @@ extension ClientError: LocalizedError {
127127
///
128128
/// - Returns: A localized string describing the client error.
129129
public var errorDescription: String? {
130-
"Client encountered an error invoking the operation \"\(operationID)\", caused by \"\(causeDescription)\", underlying error: \(underlyingError.localizedDescription)."
130+
"Client encountered an error invoking the operation \"\(operationID)\", caused by \"\(causeDescription)\", underlying error: \(underlyingError)."
131131
}
132132
}

Sources/OpenAPIRuntime/Errors/ServerError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,6 @@ extension ServerError: LocalizedError {
173173
///
174174
/// - Returns: A localized string describing the server error.
175175
public var errorDescription: String? {
176-
"Server encountered an error handling the operation \"\(operationID)\", caused by \"\(causeDescription)\", underlying error: \(underlyingError.localizedDescription)."
176+
"Server encountered an error handling the operation \"\(operationID)\", caused by \"\(causeDescription)\", underlying error: \(underlyingError)."
177177
}
178178
}

Tests/OpenAPIRuntimeTests/Errors/Test_ClientError.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
import Foundation
1516
import HTTPTypes
1617
@_spi(Generated) @testable import OpenAPIRuntime
1718
import XCTest
@@ -36,7 +37,7 @@ final class Test_ServerError: XCTestCase {
3637
)
3738
XCTAssertEqual(
3839
error.localizedDescription,
39-
"Server encountered an error handling the operation \"op\", caused by \"User handler threw an error.\", underlying error: Just errorDescription."
40+
"Server encountered an error handling the operation \"op\", caused by \"User handler threw an error.\", underlying error: Just description."
4041
)
4142
}
4243
}

Tests/OpenAPIRuntimeTests/Errors/Test_RuntimeError.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
import Foundation
1516
import HTTPTypes
1617
@_spi(Generated) @testable import OpenAPIRuntime
1718
import XCTest

Tests/OpenAPIRuntimeTests/Errors/Test_ServerError.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
import Foundation
1516
import HTTPTypes
1617
@_spi(Generated) @testable import OpenAPIRuntime
1718
import XCTest
@@ -31,7 +32,7 @@ final class Test_ClientError: XCTestCase {
3132
)
3233
XCTAssertEqual(
3334
error.localizedDescription,
34-
"Client encountered an error invoking the operation \"op\", caused by \"Transport threw an error.\", underlying error: Just errorDescription."
35+
"Client encountered an error invoking the operation \"op\", caused by \"Transport threw an error.\", underlying error: Just description."
3536
)
3637
}
3738
}

0 commit comments

Comments
 (0)