Skip to content

Commit

Permalink
Add human-readable error description for TimeoutError (#10)
Browse files Browse the repository at this point in the history
# Add human-readable error description for TimeoutError

## ♻️ Current situation & Problem
This PR adopts the LocalizedError protocol for the TimeoutError
providing a generic, localized error description and failure reason.


## ⚙️ Release Notes 
* Localize TimeoutError

## 📝 Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
Supereg authored Jun 21, 2024
1 parent db3618b commit 656f765
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import PackageDescription

let package = Package(
name: "SpeziFoundation",
defaultLocalization: "en",
platforms: [
.iOS(.v17),
.watchOS(.v10),
Expand All @@ -26,6 +27,9 @@ let package = Package(
targets: [
.target(
name: "SpeziFoundation",
resources: [
.process("Resources")
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
Expand Down
10 changes: 9 additions & 1 deletion Sources/SpeziFoundation/Misc/TimeoutError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ public struct TimeoutError {
}


extension TimeoutError: Error {}
extension TimeoutError: LocalizedError {
public var errorDescription: String? {
String(localized: LocalizedStringResource("Timeout", bundle: .atURL(Bundle.module.bundleURL)))
}

public var failureReason: String? {
String(localized: LocalizedStringResource("The operation timed out.", bundle: .atURL(Bundle.module.bundleURL)))
}
}


/// Race a timeout.
Expand Down
38 changes: 38 additions & 0 deletions Sources/SpeziFoundation/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"sourceLanguage" : "en",
"strings" : {
"The operation timed out." : {
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Der Vorgang hat das Zeitlimit überschritten."
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "The operation timed out."
}
}
}
},
"Timeout" : {
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Zeitüberschreitung"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Timeout"
}
}
}
}
},
"version" : "1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This source file is part of the Stanford Spezi open-source project

SPDX-FileCopyrightText: 2024 Stanford University and the project authors (see CONTRIBUTORS.md)

SPDX-License-Identifier: MIT

0 comments on commit 656f765

Please sign in to comment.