Skip to content

Commit acccbe5

Browse files
RISCfutureclaude
andcommitted
Guard String(localized:comment:) for Linux compatibility
Wraps the comment: parameter in String(localized:) calls with #if canImport(Darwin) since the comment parameter is not available on Linux Foundation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent abbb80a commit acccbe5

1 file changed

Lines changed: 110 additions & 0 deletions

File tree

Sources/SwiftNASR/Error.swift

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,121 +120,231 @@ extension Error: LocalizedError {
120120
public var errorDescription: String? {
121121
switch self {
122122
case .nullDistribution, .noSuchFilePrefix, .noSuchFile:
123+
#if canImport(Darwin)
123124
return String(localized: "Couldn’t load distribution.", comment: "error description")
125+
#else
126+
return String(localized: "Couldn’t load distribution.")
127+
#endif
124128
case .badResponse, .noData, .downloadFailed:
129+
#if canImport(Darwin)
125130
return String(localized: "Couldn’t download distribution.", comment: "error description")
131+
#else
132+
return String(localized: "Couldn’t download distribution.")
133+
#endif
126134
case .unknownARTCC, .unknownARTCCFrequency, .unknownFieldId,
127135
.unknownFrequencyFieldId, .invalidFrequency, .unknownFSS,
128136
.invalidRunwaySurface, .invalidPavementClassification,
129137
.invalidVGSI, .unknownNavaid, .invalidAltitudeFormat:
138+
#if canImport(Darwin)
130139
return String(localized: "Couldn’t parse distribution data.", comment: "error description")
140+
#else
141+
return String(localized: "Couldn’t parse distribution data.")
142+
#endif
131143
case .notYetLoaded:
144+
#if canImport(Darwin)
132145
return String(localized: "This NASR has not been loaded yet.", comment: "error description")
146+
#else
147+
return String(localized: "This NASR has not been loaded yet.")
148+
#endif
133149
}
134150
}
135151

136152
public var failureReason: String? {
137153
switch self {
138154
case .nullDistribution:
155+
#if canImport(Darwin)
139156
return String(
140157
localized: "Called .load() on a null distribution.",
141158
comment: "failure reason"
142159
)
160+
#else
161+
return String(localized: "Called .load() on a null distribution.")
162+
#endif
143163
case .badResponse(let response):
164+
#if canImport(Darwin)
144165
return String(
145166
localized: "Bad response: \(response.description).",
146167
comment: "failure reason"
147168
)
169+
#else
170+
return String(localized: "Bad response: \(response.description).")
171+
#endif
148172
case .downloadFailed(let reason):
173+
#if canImport(Darwin)
149174
return String(localized: "Download failed: \(reason)", comment: "failure reason")
175+
#else
176+
return String(localized: "Download failed: \(reason)")
177+
#endif
150178
case .noSuchFilePrefix(let prefix):
179+
#if canImport(Darwin)
151180
return String(
152181
localized: "Couldn’t find file in archive with prefix ‘\(prefix).’",
153182
comment: "failure reason"
154183
)
184+
#else
185+
return String(localized: "Couldn’t find file in archive with prefix ‘\(prefix).’")
186+
#endif
155187
case .noData:
188+
#if canImport(Darwin)
156189
return String(localized: "No data was downloaded.", comment: "failure reason")
190+
#else
191+
return String(localized: "No data was downloaded.")
192+
#endif
157193
case .unknownARTCC(let ID):
194+
#if canImport(Darwin)
158195
return String(
159196
localized: "Referenced undefined ARTCC record with ID ‘\(ID)’.",
160197
comment: "failure reason"
161198
)
199+
#else
200+
return String(localized: "Referenced undefined ARTCC record with ID ‘\(ID)’.")
201+
#endif
162202
case let .unknownARTCCFrequency(frequency, ARTCC):
203+
#if canImport(Darwin)
163204
return String(
164205
localized: "Referenced undefined frequency ‘\(frequency)’ for ARTCC \(ARTCC.code).",
165206
comment: "failure reason"
166207
)
208+
#else
209+
return String(localized: "Referenced undefined frequency ‘\(frequency)’ for ARTCC \(ARTCC.code).")
210+
#endif
167211
case let .unknownFieldId(fieldId, ARTCC):
212+
#if canImport(Darwin)
168213
return String(
169214
localized: "Unknown field ID ‘\(fieldId)’ at ‘\(ARTCC.code) \(ARTCC.locationName)’.",
170215
comment: "failure reason"
171216
)
217+
#else
218+
return String(localized: "Unknown field ID ‘\(fieldId)’ at ‘\(ARTCC.code) \(ARTCC.locationName)’.")
219+
#endif
172220
case let .unknownFrequencyFieldId(fieldId, frequency, ARTCC):
221+
#if canImport(Darwin)
173222
return String(
174223
localized:
175224
"Unknown field ID '\(fieldId)' for \(frequency.frequencyKHz) kHz at '\(ARTCC.code) \(ARTCC.locationName)'.",
176225
comment: "failure reason"
177226
)
227+
#else
228+
return String(
229+
localized:
230+
"Unknown field ID '\(fieldId)' for \(frequency.frequencyKHz) kHz at '\(ARTCC.code) \(ARTCC.locationName)'."
231+
)
232+
#endif
178233
case .invalidFrequency(let string):
234+
#if canImport(Darwin)
179235
return String(localized: "Invalid frequency ‘\(string)’.", comment: "failure reason")
236+
#else
237+
return String(localized: "Invalid frequency ‘\(string)’.")
238+
#endif
180239
case .unknownFSS(let ID):
240+
#if canImport(Darwin)
181241
return String(
182242
localized: "Continuation record references unknown FSS ‘\(ID)’.",
183243
comment: "failure reason"
184244
)
245+
#else
246+
return String(localized: "Continuation record references unknown FSS ‘\(ID)’.")
247+
#endif
185248
case .notYetLoaded:
249+
#if canImport(Darwin)
186250
return String(
187251
localized: "Attempted to access NASR data before .load() was called.",
188252
comment: "failure reason"
189253
)
254+
#else
255+
return String(localized: "Attempted to access NASR data before .load() was called.")
256+
#endif
190257
case .noSuchFile(let path):
258+
#if canImport(Darwin)
191259
return String(
192260
localized: "No such file in distribution: \(path).",
193261
comment: "failure reason"
194262
)
263+
#else
264+
return String(localized: "No such file in distribution: \(path).")
265+
#endif
195266
case .invalidRunwaySurface(let string):
267+
#if canImport(Darwin)
196268
return String(localized: "Unknown runway surface ‘\(string)’.", comment: "failure reason")
269+
#else
270+
return String(localized: "Unknown runway surface ‘\(string)’.")
271+
#endif
197272
case .invalidPavementClassification(let string):
273+
#if canImport(Darwin)
198274
return String(
199275
localized: "Unknown pavement classification ‘\(string)’ for PCN.",
200276
comment: "failure reason"
201277
)
278+
#else
279+
return String(localized: "Unknown pavement classification ‘\(string)’ for PCN.")
280+
#endif
202281
case .invalidVGSI(let string):
282+
#if canImport(Darwin)
203283
return String(localized: "Unknown VGSI identifier ‘\(string)’.", comment: "failure reason")
284+
#else
285+
return String(localized: "Unknown VGSI identifier ‘\(string)’.")
286+
#endif
204287
case .unknownNavaid(let string):
288+
#if canImport(Darwin)
205289
return String(localized: "Unknown navaid ‘\(string)’.", comment: "failure reason")
290+
#else
291+
return String(localized: "Unknown navaid ‘\(string)’.")
292+
#endif
206293
case .invalidAltitudeFormat(let string):
294+
#if canImport(Darwin)
207295
return String(localized: "Invalid altitude format ‘\(string)’.", comment: "failure reason")
296+
#else
297+
return String(localized: "Invalid altitude format ‘\(string)’.")
298+
#endif
208299
}
209300
}
210301

211302
public var recoverySuggestion: String? {
212303
switch self {
213304
case .nullDistribution:
305+
#if canImport(Darwin)
214306
return String(
215307
localized:
216308
"Do not call .load() on a NullDistribution. Use NullDistribution for distributions that were previously loaded and serialized to disk.",
217309
comment: "recovery suggestion"
218310
)
311+
#else
312+
return String(
313+
localized:
314+
"Do not call .load() on a NullDistribution. Use NullDistribution for distributions that were previously loaded and serialized to disk."
315+
)
316+
#endif
219317
case .badResponse, .noData, .downloadFailed:
318+
#if canImport(Darwin)
220319
return String(
221320
localized: "Verify that the URL to the distribution is correct and accessible.",
222321
comment: "recovery suggestion"
223322
)
323+
#else
324+
return String(localized: "Verify that the URL to the distribution is correct and accessible.")
325+
#endif
224326
case .unknownARTCC, .unknownARTCCFrequency, .unknownFieldId,
225327
.unknownFrequencyFieldId, .invalidFrequency, .unknownFSS,
226328
.invalidRunwaySurface, .invalidPavementClassification,
227329
.invalidVGSI, .unknownNavaid, .noSuchFilePrefix, .noSuchFile,
228330
.invalidAltitudeFormat:
331+
#if canImport(Darwin)
229332
return String(
230333
localized: "The NASR FADDS format may have changed, requiring an update to SwiftNASR.",
231334
comment: "recovery suggestion"
232335
)
336+
#else
337+
return String(localized: "The NASR FADDS format may have changed, requiring an update to SwiftNASR.")
338+
#endif
233339
case .notYetLoaded:
340+
#if canImport(Darwin)
234341
return String(
235342
localized: "Call .load() before accessing NASR data.",
236343
comment: "recovery suggestion"
237344
)
345+
#else
346+
return String(localized: "Call .load() before accessing NASR data.")
347+
#endif
238348
}
239349
}
240350
}

0 commit comments

Comments
 (0)