Skip to content

Commit a3766db

Browse files
committed
Get full Linux (& potentially other platform) compatibility
1 parent 215af2d commit a3766db

22 files changed

+605
-343
lines changed

Package.resolved

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,20 @@ let package = Package(
66
defaultLocalization: "en",
77
platforms: [.macOS(.v13), .iOS(.v16), .tvOS(.v16), .watchOS(.v9), .macCatalyst(.v16)],
88
products: [.library(name: "ErrorKit", targets: ["ErrorKit"])],
9+
dependencies: [
10+
// CryptoKit is not available on Linux, so we need Swift Crypto
11+
.package(url: "https://github.com/apple/swift-crypto.git", from: "3.11.0"),
12+
],
913
targets: [
1014
.target(
1115
name: "ErrorKit",
16+
dependencies: [
17+
.product(
18+
name: "Crypto",
19+
package: "swift-crypto",
20+
condition: .when(platforms: [.android, .linux, .openbsd, .wasi, .windows])
21+
),
22+
],
1223
resources: [.process("Resources/Localizable.xcstrings")]
1324
),
1425
.testTarget(name: "ErrorKitTests", dependencies: ["ErrorKit"]),

Sources/ErrorKit/BuiltInErrors/DatabaseError.swift

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,29 +136,25 @@ public enum DatabaseError: Throwable, Catching {
136136
public var userFriendlyMessage: String {
137137
switch self {
138138
case .connectionFailed:
139-
return String(
140-
localized: "BuiltInErrors.DatabaseError.connectionFailed",
141-
defaultValue: "Unable to establish a connection to the database. Check your network settings and try again.",
142-
bundle: .module
139+
return String.localized(
140+
key: "BuiltInErrors.DatabaseError.connectionFailed",
141+
defaultValue: "Unable to establish a connection to the database. Check your network settings and try again."
143142
)
144143
case .operationFailed(let context):
145-
return String(
146-
localized: "BuiltInErrors.DatabaseError.operationFailed",
147-
defaultValue: "The database operation for \(context) could not be completed. Please retry the action.",
148-
bundle: .module
144+
return String.localized(
145+
key: "BuiltInErrors.DatabaseError.operationFailed",
146+
defaultValue: "The database operation for \(context) could not be completed. Please retry the action."
149147
)
150148
case .recordNotFound(let entity, let identifier):
151149
if let identifier {
152-
return String(
153-
localized: "BuiltInErrors.DatabaseError.recordNotFoundWithID",
154-
defaultValue: "The \(entity) record with ID \(identifier) was not found in the database. Verify the details and try again.",
155-
bundle: .module
150+
return String.localized(
151+
key: "BuiltInErrors.DatabaseError.recordNotFoundWithID",
152+
defaultValue: "The \(entity) record with ID \(identifier) was not found in the database. Verify the details and try again."
156153
)
157154
} else {
158-
return String(
159-
localized: "BuiltInErrors.DatabaseError.recordNotFound",
160-
defaultValue: "The \(entity) record was not found in the database. Verify the details and try again.",
161-
bundle: .module
155+
return String.localized(
156+
key: "BuiltInErrors.DatabaseError.recordNotFound",
157+
defaultValue: "The \(entity) record was not found in the database. Verify the details and try again."
162158
)
163159
}
164160
case .generic(let userFriendlyMessage):

Sources/ErrorKit/BuiltInErrors/FileError.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,19 @@ public enum FileError: Throwable, Catching {
128128
public var userFriendlyMessage: String {
129129
switch self {
130130
case .fileNotFound(let fileName):
131-
return String(
132-
localized: "BuiltInErrors.FileError.fileNotFound",
133-
defaultValue: "The file \(fileName) could not be located. Please verify the file path and try again.",
134-
bundle: .module
131+
return String.localized(
132+
key: "BuiltInErrors.FileError.fileNotFound",
133+
defaultValue: "The file \(fileName) could not be located. Please verify the file path and try again."
135134
)
136135
case .readFailed(let fileName):
137-
return String(
138-
localized: "BuiltInErrors.FileError.readError",
139-
defaultValue: "An error occurred while attempting to read the file \(fileName). Please check file permissions and try again.",
140-
bundle: .module
136+
return String.localized(
137+
key: "BuiltInErrors.FileError.readError",
138+
defaultValue: "An error occurred while attempting to read the file \(fileName). Please check file permissions and try again."
141139
)
142140
case .writeFailed(let fileName):
143-
return String(
144-
localized: "BuiltInErrors.FileError.writeError",
145-
defaultValue: "Unable to write to the file \(fileName). Ensure you have the necessary permissions and try again.",
146-
bundle: .module
141+
return String.localized(
142+
key: "BuiltInErrors.FileError.writeError",
143+
defaultValue: "Unable to write to the file \(fileName). Ensure you have the necessary permissions and try again."
147144
)
148145
case .generic(let userFriendlyMessage):
149146
return userFriendlyMessage

Sources/ErrorKit/BuiltInErrors/NetworkError.swift

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -178,39 +178,38 @@ public enum NetworkError: Throwable, Catching {
178178
public var userFriendlyMessage: String {
179179
switch self {
180180
case .noInternet:
181-
return String(
182-
localized: "BuiltInErrors.NetworkError.noInternet",
183-
defaultValue: "Unable to connect to the internet. Please check your network settings and try again.",
184-
bundle: .module
181+
return String.localized(
182+
key: "BuiltInErrors.NetworkError.noInternet",
183+
defaultValue: "Unable to connect to the internet. Please check your network settings and try again."
185184
)
186185
case .timeout:
187-
return String(
188-
localized: "BuiltInErrors.NetworkError.timeout",
189-
defaultValue: "The network request took too long to complete. Please check your connection and try again.",
190-
bundle: .module
186+
return String.localized(
187+
key: "BuiltInErrors.NetworkError.timeout",
188+
defaultValue: "The network request took too long to complete. Please check your connection and try again."
191189
)
192190
case .badRequest(let code, let message):
193-
return String(
194-
localized: "BuiltInErrors.NetworkError.badRequest",
195-
defaultValue: "There was an issue with the request (Code: \(code)). \(message). Please review and retry.",
196-
bundle: .module
191+
return String.localized(
192+
key: "BuiltInErrors.NetworkError.badRequest",
193+
defaultValue: "There was an issue with the request (Code: \(code)). \(message). Please review and retry."
197194
)
198195
case .serverError(let code, let message):
199-
let defaultMessage = String(
200-
localized: "BuiltInErrors.NetworkError.serverError",
201-
defaultValue: "The server encountered an error (Code: \(code)). ",
202-
bundle: .module
196+
let defaultMessage = String.localized(
197+
key: "BuiltInErrors.NetworkError.serverError",
198+
defaultValue: "The server encountered an error (Code: \(code)). "
203199
)
200+
204201
if let message = message {
205202
return defaultMessage + message
206203
} else {
207-
return defaultMessage + "Please try again later."
204+
return defaultMessage + String.localized(
205+
key: "Common.Message.tryAgainLater",
206+
defaultValue: "Please try again later."
207+
)
208208
}
209209
case .decodingFailure:
210-
return String(
211-
localized: "BuiltInErrors.NetworkError.decodingFailure",
212-
defaultValue: "Unable to process the server's response. Please try again or contact support if the issue persists.",
213-
bundle: .module
210+
return String.localized(
211+
key: "BuiltInErrors.NetworkError.decodingFailure",
212+
defaultValue: "Unable to process the server's response. Please try again or contact support if the issue persists."
214213
)
215214
case .generic(let userFriendlyMessage):
216215
return userFriendlyMessage

Sources/ErrorKit/BuiltInErrors/OperationError.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,14 @@ public enum OperationError: Throwable, Catching {
108108
public var userFriendlyMessage: String {
109109
switch self {
110110
case .dependencyFailed(let dependency):
111-
return String(
112-
localized: "BuiltInErrors.OperationError.dependencyFailed",
113-
defaultValue: "The operation could not be started because a required component failed to initialize: \(dependency). Please restart the application or contact support.",
114-
bundle: .module
111+
return String.localized(
112+
key: "BuiltInErrors.OperationError.dependencyFailed",
113+
defaultValue: "The operation could not be started because a required component failed to initialize: \(dependency). Please restart the application or contact support."
115114
)
116115
case .canceled:
117-
return String(
118-
localized: "BuiltInErrors.OperationError.canceled",
119-
defaultValue: "The operation was canceled at your request. You can retry the action if needed.",
120-
bundle: .module
116+
return String.localized(
117+
key: "BuiltInErrors.OperationError.canceled",
118+
defaultValue: "The operation was canceled at your request. You can retry the action if needed."
121119
)
122120
case .generic(let userFriendlyMessage):
123121
return userFriendlyMessage

Sources/ErrorKit/BuiltInErrors/ParsingError.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,14 @@ public enum ParsingError: Throwable, Catching {
108108
public var userFriendlyMessage: String {
109109
switch self {
110110
case .invalidInput(let input):
111-
return String(
112-
localized: "BuiltInErrors.ParsingError.invalidInput",
113-
defaultValue: "The provided input could not be processed correctly: \(input). Please review the input and ensure it matches the expected format.",
114-
bundle: .module
111+
return String.localized(
112+
key: "BuiltInErrors.ParsingError.invalidInput",
113+
defaultValue: "The provided input could not be processed correctly: \(input). Please review the input and ensure it matches the expected format."
115114
)
116115
case .missingField(let field):
117-
return String(
118-
localized: "BuiltInErrors.ParsingError.missingField",
119-
defaultValue: "The required information is incomplete. The \(field) field is missing and must be provided to continue.",
120-
bundle: .module
116+
return String.localized(
117+
key: "BuiltInErrors.ParsingError.missingField",
118+
defaultValue: "The required information is incomplete. The \(field) field is missing and must be provided to continue."
121119
)
122120
case .generic(let userFriendlyMessage):
123121
return userFriendlyMessage

Sources/ErrorKit/BuiltInErrors/PermissionError.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,19 @@ public enum PermissionError: Throwable, Catching {
129129
public var userFriendlyMessage: String {
130130
switch self {
131131
case .denied(let permission):
132-
return String(
133-
localized: "BuiltInErrors.PermissionError.denied",
134-
defaultValue: "Access to \(permission) was declined. To use this feature, please enable the permission in your device Settings.",
135-
bundle: .module
132+
return String.localized(
133+
key: "BuiltInErrors.PermissionError.denied",
134+
defaultValue: "Access to \(permission) was declined. To use this feature, please enable the permission in your device Settings."
136135
)
137136
case .restricted(let permission):
138-
return String(
139-
localized: "BuiltInErrors.PermissionError.restricted",
140-
defaultValue: "Access to \(permission) is currently restricted. This may be due to system settings or parental controls.",
141-
bundle: .module
137+
return String.localized(
138+
key: "BuiltInErrors.PermissionError.restricted",
139+
defaultValue: "Access to \(permission) is currently restricted. This may be due to system settings or parental controls."
142140
)
143141
case .notDetermined(let permission):
144-
return String(
145-
localized: "BuiltInErrors.PermissionError.notDetermined",
146-
defaultValue: "Permission for \(permission) has not been confirmed. Please review and grant access in your device Settings.",
147-
bundle: .module
142+
return String.localized(
143+
key: "BuiltInErrors.PermissionError.notDetermined",
144+
defaultValue: "Permission for \(permission) has not been confirmed. Please review and grant access in your device Settings."
148145
)
149146
case .generic(let userFriendlyMessage):
150147
return userFriendlyMessage

Sources/ErrorKit/BuiltInErrors/StateError.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,19 @@ public enum StateError: Throwable, Catching {
122122
public var userFriendlyMessage: String {
123123
switch self {
124124
case .invalidState(let description):
125-
return String(
126-
localized: "BuiltInErrors.StateError.invalidState",
127-
defaultValue: "The current state prevents this action: \(description). Please ensure all requirements are met and try again.",
128-
bundle: .module
125+
return String.localized(
126+
key: "BuiltInErrors.StateError.invalidState",
127+
defaultValue: "The current state prevents this action: \(description). Please ensure all requirements are met and try again."
129128
)
130129
case .alreadyFinalized:
131-
return String(
132-
localized: "BuiltInErrors.StateError.alreadyFinalized",
133-
defaultValue: "This item has already been finalized and cannot be modified. Please create a new version if changes are needed.",
134-
bundle: .module
130+
return String.localized(
131+
key: "BuiltInErrors.StateError.alreadyFinalized",
132+
defaultValue: "This item has already been finalized and cannot be modified. Please create a new version if changes are needed."
135133
)
136134
case .preconditionFailed(let description):
137-
return String(
138-
localized: "BuiltInErrors.StateError.preconditionFailed",
139-
defaultValue: "A required condition was not met: \(description). Please complete all prerequisites before proceeding.",
140-
bundle: .module
135+
return String.localized(
136+
key: "BuiltInErrors.StateError.preconditionFailed",
137+
defaultValue: "A required condition was not met: \(description). Please complete all prerequisites before proceeding."
141138
)
142139
case .generic(let userFriendlyMessage):
143140
return userFriendlyMessage

Sources/ErrorKit/BuiltInErrors/ValidationError.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,22 +136,19 @@ public enum ValidationError: Throwable, Catching {
136136
public var userFriendlyMessage: String {
137137
switch self {
138138
case .invalidInput(let field):
139-
return String(
140-
localized: "BuiltInErrors.ValidationError.invalidInput",
141-
defaultValue: "The value entered for \(field) is not in the correct format. Please review the requirements and try again.",
142-
bundle: .module
139+
return String.localized(
140+
key: "BuiltInErrors.ValidationError.invalidInput",
141+
defaultValue: "The value entered for \(field) is not in the correct format. Please review the requirements and try again."
143142
)
144143
case .missingField(let field):
145-
return String(
146-
localized: "BuiltInErrors.ValidationError.missingField",
147-
defaultValue: "Please provide a value for \(field). This information is required to proceed.",
148-
bundle: .module
144+
return String.localized(
145+
key: "BuiltInErrors.ValidationError.missingField",
146+
defaultValue: "Please provide a value for \(field). This information is required to proceed."
149147
)
150148
case .inputTooLong(let field, let maxLength):
151-
return String(
152-
localized: "BuiltInErrors.ValidationError.inputTooLong",
153-
defaultValue: "The \(field) field cannot be longer than \(maxLength) characters. Please shorten your input and try again.",
154-
bundle: .module
149+
return String.localized(
150+
key: "BuiltInErrors.ValidationError.inputTooLong",
151+
defaultValue: "The \(field) field cannot be longer than \(maxLength) characters. Please shorten your input and try again."
155152
)
156153
case .generic(let userFriendlyMessage):
157154
return userFriendlyMessage

0 commit comments

Comments
 (0)