-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathNSError.swift
3330 lines (2798 loc) · 107 KB
/
NSError.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
@_exported import Foundation // Clang module
import CoreFoundation
import Darwin
@_implementationOnly import _SwiftFoundationOverlayShims
//===----------------------------------------------------------------------===//
// NSError (as an out parameter).
//===----------------------------------------------------------------------===//
public typealias NSErrorPointer = AutoreleasingUnsafeMutablePointer<NSError?>?
// Note: NSErrorPointer becomes ErrorPointer in Swift 3.
public typealias ErrorPointer = NSErrorPointer
// An error value to use when an Objective-C API indicates error
// but produces a nil error object.
// This is 'internal' rather than 'private' for no other reason but to make the
// type print more nicely. It's not part of the ABI, so if type printing of
// private things improves we can change it.
internal enum _GenericObjCError : Error {
case nilError
}
// A cached instance of the above in order to save on the conversion to Error.
private let _nilObjCError: Error = _GenericObjCError.nilError
public // COMPILER_INTRINSIC
func _convertNSErrorToError(_ error: NSError?) -> Error {
if let error = error {
return error
}
return _nilObjCError
}
public // COMPILER_INTRINSIC
func _convertErrorToNSError(_ error: Error) -> NSError {
return unsafeDowncast(_bridgeErrorToNSError(error), to: NSError.self)
}
/// Describes an error that provides localized messages describing why
/// an error occurred and provides more information about the error.
public protocol LocalizedError : Error {
/// A localized message describing what error occurred.
var errorDescription: String? { get }
/// A localized message describing the reason for the failure.
var failureReason: String? { get }
/// A localized message describing how one might recover from the failure.
var recoverySuggestion: String? { get }
/// A localized message providing "help" text if the user requests help.
var helpAnchor: String? { get }
}
public extension LocalizedError {
var errorDescription: String? { return nil }
var failureReason: String? { return nil }
var recoverySuggestion: String? { return nil }
var helpAnchor: String? { return nil }
}
/// Class that implements the informal protocol
/// NSErrorRecoveryAttempting, which is used by NSError when it
/// attempts recovery from an error.
// NOTE: older overlays called this class _NSErrorRecoveryAttempter.
// The two must coexist without a conflicting ObjC class name, so it
// was renamed. The old name must not be used in the new runtime.
class __NSErrorRecoveryAttempter {
@objc(attemptRecoveryFromError:optionIndex:delegate:didRecoverSelector:contextInfo:)
func attemptRecovery(fromError nsError: NSError,
optionIndex recoveryOptionIndex: Int,
delegate: AnyObject?,
didRecoverSelector: Selector,
contextInfo: UnsafeMutableRawPointer?) {
let error = nsError as Error as! RecoverableError
error.attemptRecovery(optionIndex: recoveryOptionIndex) { success in
__NSErrorPerformRecoverySelector(delegate, didRecoverSelector, success, contextInfo)
}
}
@objc(attemptRecoveryFromError:optionIndex:)
func attemptRecovery(fromError nsError: NSError,
optionIndex recoveryOptionIndex: Int) -> Bool {
let error = nsError as Error as! RecoverableError
return error.attemptRecovery(optionIndex: recoveryOptionIndex)
}
}
/// Describes an error that may be recoverable by presenting several
/// potential recovery options to the user.
public protocol RecoverableError : Error {
/// Provides a set of possible recovery options to present to the user.
var recoveryOptions: [String] { get }
/// Attempt to recover from this error when the user selected the
/// option at the given index. This routine must call handler and
/// indicate whether recovery was successful (or not).
///
/// This entry point is used for recovery of errors handled at a
/// "document" granularity, that do not affect the entire
/// application.
func attemptRecovery(optionIndex recoveryOptionIndex: Int,
resultHandler handler: @escaping (_ recovered: Bool) -> Void)
/// Attempt to recover from this error when the user selected the
/// option at the given index. Returns true to indicate
/// successful recovery, and false otherwise.
///
/// This entry point is used for recovery of errors handled at
/// the "application" granularity, where nothing else in the
/// application can proceed until the attempted error recovery
/// completes.
func attemptRecovery(optionIndex recoveryOptionIndex: Int) -> Bool
}
public extension RecoverableError {
/// Default implementation that uses the application-model recovery
/// mechanism (``attemptRecovery(optionIndex:)``) to implement
/// document-modal recovery.
func attemptRecovery(optionIndex recoveryOptionIndex: Int,
resultHandler handler: @escaping (_ recovered: Bool) -> Void) {
handler(attemptRecovery(optionIndex: recoveryOptionIndex))
}
}
/// Describes an error type that specifically provides a domain, code,
/// and user-info dictionary.
public protocol CustomNSError : Error {
/// The domain of the error.
static var errorDomain: String { get }
/// The error code within the given domain.
var errorCode: Int { get }
/// The user-info dictionary.
var errorUserInfo: [String : Any] { get }
}
public extension CustomNSError {
/// Default domain of the error.
static var errorDomain: String {
return String(reflecting: self)
}
/// The error code within the given domain.
var errorCode: Int {
return _getDefaultErrorCode(self)
}
/// The default user-info dictionary.
var errorUserInfo: [String : Any] {
return [:]
}
}
/// Convert an arbitrary binary integer to an Int, reinterpreting signed
/// -> unsigned if needed but trapping if the result is otherwise not
/// expressible.
func unsafeBinaryIntegerToInt<T: BinaryInteger>(_ value: T) -> Int {
if T.isSigned {
return numericCast(value)
}
let uintValue: UInt = numericCast(value)
return Int(bitPattern: uintValue)
}
/// Convert from an Int to an arbitrary binary integer, reinterpreting signed ->
/// unsigned if needed but trapping if the result is otherwise not expressible.
func unsafeBinaryIntegerFromInt<T: BinaryInteger>(_ value: Int) -> T {
if T.isSigned {
return numericCast(value)
}
let uintValue = UInt(bitPattern: value)
return numericCast(uintValue)
}
extension CustomNSError
where Self: RawRepresentable, Self.RawValue: FixedWidthInteger {
// The error code of Error with integral raw values is the raw value.
public var errorCode: Int {
return unsafeBinaryIntegerToInt(self.rawValue)
}
}
public extension Error where Self : CustomNSError {
/// Default implementation for customized NSErrors.
var _domain: String { return Self.errorDomain }
/// Default implementation for customized NSErrors.
var _code: Int { return self.errorCode }
}
public extension Error where Self: CustomNSError, Self: RawRepresentable,
Self.RawValue: FixedWidthInteger {
/// Default implementation for customized NSErrors.
var _code: Int { return self.errorCode }
}
public extension Error {
/// Retrieve the localized description for this error.
var localizedDescription: String {
return (self as NSError).localizedDescription
}
}
internal let _errorDomainUserInfoProviderQueue = DispatchQueue(
label: "SwiftFoundation._errorDomainUserInfoProviderQueue")
/// Retrieve the default userInfo dictionary for a given error.
public func _getErrorDefaultUserInfo<T: Error>(_ error: T)
-> AnyObject? {
let hasUserInfoValueProvider: Bool
// If the OS supports user info value providers, use those
// to lazily populate the user-info dictionary for this domain.
if #available(macOS 10.11, iOS 9.0, tvOS 9.0, watchOS 2.0, *) {
// Note: the Cocoa error domain specifically excluded from
// user-info value providers.
let domain = error._domain
if domain != NSCocoaErrorDomain {
_errorDomainUserInfoProviderQueue.sync {
if NSError.userInfoValueProvider(forDomain: domain) != nil { return }
NSError.setUserInfoValueProvider(forDomain: domain) { (error, key) in
switch key {
case NSLocalizedDescriptionKey:
return (error as? LocalizedError)?.errorDescription
case NSLocalizedFailureReasonErrorKey:
return (error as? LocalizedError)?.failureReason
case NSLocalizedRecoverySuggestionErrorKey:
return (error as? LocalizedError)?.recoverySuggestion
case NSHelpAnchorErrorKey:
return (error as? LocalizedError)?.helpAnchor
case NSLocalizedRecoveryOptionsErrorKey:
return (error as? RecoverableError)?.recoveryOptions
case NSRecoveryAttempterErrorKey:
if error is RecoverableError {
return __NSErrorRecoveryAttempter()
}
return nil
default:
return nil
}
}
}
assert(NSError.userInfoValueProvider(forDomain: domain) != nil)
hasUserInfoValueProvider = true
} else {
hasUserInfoValueProvider = false
}
} else {
hasUserInfoValueProvider = false
}
// Populate the user-info dictionary
var result: [String : Any]
// Initialize with custom user-info.
if let customNSError = error as? CustomNSError {
result = customNSError.errorUserInfo
} else {
result = [:]
}
// Handle localized errors. If we registered a user-info value
// provider, these will computed lazily.
if !hasUserInfoValueProvider,
let localizedError = error as? LocalizedError {
if let description = localizedError.errorDescription {
result[NSLocalizedDescriptionKey] = description
}
if let reason = localizedError.failureReason {
result[NSLocalizedFailureReasonErrorKey] = reason
}
if let suggestion = localizedError.recoverySuggestion {
result[NSLocalizedRecoverySuggestionErrorKey] = suggestion
}
if let helpAnchor = localizedError.helpAnchor {
result[NSHelpAnchorErrorKey] = helpAnchor
}
}
// Handle recoverable errors. If we registered a user-info value
// provider, these will computed lazily.
if !hasUserInfoValueProvider,
let recoverableError = error as? RecoverableError {
result[NSLocalizedRecoveryOptionsErrorKey] =
recoverableError.recoveryOptions
result[NSRecoveryAttempterErrorKey] = __NSErrorRecoveryAttempter()
}
return result as AnyObject
}
// NSError and CFError conform to the standard Error protocol. Compiler
// magic allows this to be done as a "toll-free" conversion when an NSError
// or CFError is used as an Error existential.
extension NSError : Error {
@nonobjc
public var _domain: String { return domain }
@nonobjc
public var _code: Int { return code }
@nonobjc
public var _userInfo: AnyObject? { return userInfo as NSDictionary }
/// The "embedded" NSError is itself.
@nonobjc
public func _getEmbeddedNSError() -> AnyObject? {
return self
}
}
extension CFError : Error {
public var _domain: String {
return CFErrorGetDomain(self) as String
}
public var _code: Int {
return CFErrorGetCode(self)
}
public var _userInfo: AnyObject? {
return CFErrorCopyUserInfo(self) as AnyObject
}
/// The "embedded" NSError is itself.
public func _getEmbeddedNSError() -> AnyObject? {
return self
}
}
/// An internal protocol to represent Swift error enums that map to standard
/// Cocoa NSError domains.
public protocol _ObjectiveCBridgeableError : Error {
/// Produce a value of the error type corresponding to the given NSError,
/// or return nil if it cannot be bridged.
init?(_bridgedNSError: __shared NSError)
}
/// A hook for the runtime to use _ObjectiveCBridgeableError in order to
/// attempt an "errorTypeValue as? SomeError" cast.
///
/// If the bridge succeeds, the bridged value is written to the uninitialized
/// memory pointed to by 'out', and true is returned. Otherwise, 'out' is
/// left uninitialized, and false is returned.
public func _bridgeNSErrorToError<
T : _ObjectiveCBridgeableError
>(_ error: NSError, out: UnsafeMutablePointer<T>) -> Bool {
if let bridged = T(_bridgedNSError: error) {
out.initialize(to: bridged)
return true
} else {
return false
}
}
/// Describes a raw representable type that is bridged to a particular
/// NSError domain.
///
/// This protocol is used primarily to generate the conformance to
/// _ObjectiveCBridgeableError for such an enum defined in Swift.
public protocol _BridgedNSError :
_ObjectiveCBridgeableError, RawRepresentable, Hashable
where Self.RawValue: FixedWidthInteger {
/// The NSError domain to which this type is bridged.
static var _nsErrorDomain: String { get }
}
extension _BridgedNSError {
public var _domain: String { return Self._nsErrorDomain }
}
extension _BridgedNSError where Self.RawValue: FixedWidthInteger {
public var _code: Int { return Int(rawValue) }
public init?(_bridgedNSError: __shared NSError) {
if _bridgedNSError.domain != Self._nsErrorDomain {
return nil
}
self.init(rawValue: RawValue(_bridgedNSError.code))
}
public func hash(into hasher: inout Hasher) {
hasher.combine(_code)
}
}
/// Describes a bridged error that stores the underlying NSError, so
/// it can be queried.
public protocol _BridgedStoredNSError :
_ObjectiveCBridgeableError, CustomNSError, Hashable {
/// The type of an error code.
associatedtype Code: _ErrorCodeProtocol, RawRepresentable
where Code.RawValue: FixedWidthInteger
//// Retrieves the embedded NSError.
var _nsError: NSError { get }
/// Create a new instance of the error type with the given embedded
/// NSError.
///
/// The \c error must have the appropriate domain for this error
/// type.
init(_nsError error: NSError)
}
/// Various helper implementations for _BridgedStoredNSError
extension _BridgedStoredNSError {
public var code: Code {
return Code(rawValue: unsafeBinaryIntegerFromInt(_nsError.code))!
}
/// Initialize an error within this domain with the given ``code``
/// and ``userInfo``.
public init(_ code: Code, userInfo: [String : Any] = [:]) {
self.init(_nsError: NSError(domain: Self.errorDomain,
code: unsafeBinaryIntegerToInt(code.rawValue),
userInfo: userInfo))
}
/// The user-info dictionary for an error that was bridged from
/// NSError.
public var userInfo: [String : Any] { return errorUserInfo }
}
/// Implementation of _ObjectiveCBridgeableError for all _BridgedStoredNSErrors.
extension _BridgedStoredNSError {
/// Default implementation of ``init(_bridgedNSError:)`` to provide
/// bridging from NSError.
public init?(_bridgedNSError error: NSError) {
if error.domain != Self.errorDomain {
return nil
}
self.init(_nsError: error)
}
}
/// Implementation of CustomNSError for all _BridgedStoredNSErrors.
public extension _BridgedStoredNSError {
// FIXME: Would prefer to have a clear "extract an NSError
// directly" operation.
// Synthesized by the compiler.
// static var errorDomain: String
var errorCode: Int { return _nsError.code }
var errorUserInfo: [String : Any] {
var result: [String : Any] = [:]
for (key, value) in _nsError.userInfo {
result[key] = value
}
return result
}
}
/// Implementation of Hashable for all _BridgedStoredNSErrors.
extension _BridgedStoredNSError {
public func hash(into hasher: inout Hasher) {
hasher.combine(_nsError)
}
@_alwaysEmitIntoClient public var hashValue: Int {
return _nsError.hashValue
}
}
/// Describes the code of an error.
public protocol _ErrorCodeProtocol : Equatable {
/// The corresponding error code.
associatedtype _ErrorType: _BridgedStoredNSError where _ErrorType.Code == Self
}
extension _ErrorCodeProtocol {
/// Allow one to match an error code against an arbitrary error.
public static func ~=(match: Self, error: Error) -> Bool {
guard let specificError = error as? Self._ErrorType else { return false }
return match == specificError.code
}
}
extension _BridgedStoredNSError {
/// Retrieve the embedded NSError from a bridged, stored NSError.
public func _getEmbeddedNSError() -> AnyObject? {
return _nsError
}
public static func == (lhs: Self, rhs: Self) -> Bool {
return lhs._nsError.isEqual(rhs._nsError)
}
}
extension _SwiftNewtypeWrapper where Self.RawValue == Error {
@inlinable // FIXME(sil-serialize-all)
public func _bridgeToObjectiveC() -> NSError {
return rawValue as NSError
}
@inlinable // FIXME(sil-serialize-all)
public static func _forceBridgeFromObjectiveC(
_ source: NSError,
result: inout Self?
) {
result = Self(rawValue: source)
}
@inlinable // FIXME(sil-serialize-all)
public static func _conditionallyBridgeFromObjectiveC(
_ source: NSError,
result: inout Self?
) -> Bool {
result = Self(rawValue: source)
return result != nil
}
@inlinable // FIXME(sil-serialize-all)
@_effects(readonly)
public static func _unconditionallyBridgeFromObjectiveC(
_ source: NSError?
) -> Self {
return Self(rawValue: _convertNSErrorToError(source))!
}
}
@available(*, unavailable, renamed: "CocoaError")
public typealias NSCocoaError = CocoaError
/// Describes errors within the Cocoa error domain.
public struct CocoaError : _BridgedStoredNSError {
public let _nsError: NSError
public init(_nsError error: NSError) {
precondition(error.domain == NSCocoaErrorDomain)
self._nsError = error
}
public static var errorDomain: String { return NSCocoaErrorDomain }
public var hashValue: Int {
return _nsError.hashValue
}
/// The error code itself.
public struct Code : RawRepresentable, Hashable, _ErrorCodeProtocol {
public typealias _ErrorType = CocoaError
public let rawValue: Int
public init(rawValue: Int) {
self.rawValue = rawValue
}
}
}
public extension CocoaError {
private var _nsUserInfo: [AnyHashable : Any] {
return (self as NSError).userInfo
}
/// The file path associated with the error, if any.
var filePath: String? {
return _nsUserInfo[NSFilePathErrorKey as NSString] as? String
}
/// The string encoding associated with this error, if any.
var stringEncoding: String.Encoding? {
return (_nsUserInfo[NSStringEncodingErrorKey as NSString] as? NSNumber)
.map { String.Encoding(rawValue: $0.uintValue) }
}
/// The underlying error behind this error, if any.
var underlying: Error? {
return _nsUserInfo[NSUnderlyingErrorKey as NSString] as? Error
}
/// The URL associated with this error, if any.
var url: URL? {
return _nsUserInfo[NSURLErrorKey as NSString] as? URL
}
}
extension CocoaError {
public static func error(_ code: CocoaError.Code, userInfo: [AnyHashable : Any]? = nil, url: URL? = nil) -> Error {
var info: [String : Any] = userInfo as? [String : Any] ?? [:]
if let url = url {
info[NSURLErrorKey] = url
}
return NSError(domain: NSCocoaErrorDomain, code: code.rawValue, userInfo: info)
}
}
extension CocoaError.Code {
public static var fileNoSuchFile: CocoaError.Code {
return CocoaError.Code(rawValue: 4)
}
public static var fileLocking: CocoaError.Code {
return CocoaError.Code(rawValue: 255)
}
public static var fileReadUnknown: CocoaError.Code {
return CocoaError.Code(rawValue: 256)
}
public static var fileReadNoPermission: CocoaError.Code {
return CocoaError.Code(rawValue: 257)
}
public static var fileReadInvalidFileName: CocoaError.Code {
return CocoaError.Code(rawValue: 258)
}
public static var fileReadCorruptFile: CocoaError.Code {
return CocoaError.Code(rawValue: 259)
}
public static var fileReadNoSuchFile: CocoaError.Code {
return CocoaError.Code(rawValue: 260)
}
public static var fileReadInapplicableStringEncoding: CocoaError.Code {
return CocoaError.Code(rawValue: 261)
}
public static var fileReadUnsupportedScheme: CocoaError.Code {
return CocoaError.Code(rawValue: 262)
}
@available(macOS, introduced: 10.5) @available(iOS, introduced: 2.0)
public static var fileReadTooLarge: CocoaError.Code {
return CocoaError.Code(rawValue: 263)
}
@available(macOS, introduced: 10.5) @available(iOS, introduced: 2.0)
public static var fileReadUnknownStringEncoding: CocoaError.Code {
return CocoaError.Code(rawValue: 264)
}
public static var fileWriteUnknown: CocoaError.Code {
return CocoaError.Code(rawValue: 512)
}
public static var fileWriteNoPermission: CocoaError.Code {
return CocoaError.Code(rawValue: 513)
}
public static var fileWriteInvalidFileName: CocoaError.Code {
return CocoaError.Code(rawValue: 514)
}
@available(macOS, introduced: 10.7) @available(iOS, introduced: 5.0)
public static var fileWriteFileExists: CocoaError.Code {
return CocoaError.Code(rawValue: 516)
}
public static var fileWriteInapplicableStringEncoding: CocoaError.Code {
return CocoaError.Code(rawValue: 517)
}
public static var fileWriteUnsupportedScheme: CocoaError.Code {
return CocoaError.Code(rawValue: 518)
}
public static var fileWriteOutOfSpace: CocoaError.Code {
return CocoaError.Code(rawValue: 640)
}
@available(macOS, introduced: 10.6) @available(iOS, introduced: 4.0)
public static var fileWriteVolumeReadOnly: CocoaError.Code {
return CocoaError.Code(rawValue: 642)
}
@available(macOS, introduced: 10.11) @available(iOS, unavailable)
public static var fileManagerUnmountUnknown: CocoaError.Code {
return CocoaError.Code(rawValue: 768)
}
@available(macOS, introduced: 10.11) @available(iOS, unavailable)
public static var fileManagerUnmountBusy: CocoaError.Code {
return CocoaError.Code(rawValue: 769)
}
public static var keyValueValidation: CocoaError.Code {
return CocoaError.Code(rawValue: 1024)
}
public static var formatting: CocoaError.Code {
return CocoaError.Code(rawValue: 2048)
}
public static var userCancelled: CocoaError.Code {
return CocoaError.Code(rawValue: 3072)
}
@available(macOS, introduced: 10.8) @available(iOS, introduced: 6.0)
public static var featureUnsupported: CocoaError.Code {
return CocoaError.Code(rawValue: 3328)
}
@available(macOS, introduced: 10.5) @available(iOS, introduced: 2.0)
public static var executableNotLoadable: CocoaError.Code {
return CocoaError.Code(rawValue: 3584)
}
@available(macOS, introduced: 10.5) @available(iOS, introduced: 2.0)
public static var executableArchitectureMismatch: CocoaError.Code {
return CocoaError.Code(rawValue: 3585)
}
@available(macOS, introduced: 10.5) @available(iOS, introduced: 2.0)
public static var executableRuntimeMismatch: CocoaError.Code {
return CocoaError.Code(rawValue: 3586)
}
@available(macOS, introduced: 10.5) @available(iOS, introduced: 2.0)
public static var executableLoad: CocoaError.Code {
return CocoaError.Code(rawValue: 3587)
}
@available(macOS, introduced: 10.5) @available(iOS, introduced: 2.0)
public static var executableLink: CocoaError.Code {
return CocoaError.Code(rawValue: 3588)
}
@available(macOS, introduced: 10.6) @available(iOS, introduced: 4.0)
public static var propertyListReadCorrupt: CocoaError.Code {
return CocoaError.Code(rawValue: 3840)
}
@available(macOS, introduced: 10.6) @available(iOS, introduced: 4.0)
public static var propertyListReadUnknownVersion: CocoaError.Code {
return CocoaError.Code(rawValue: 3841)
}
@available(macOS, introduced: 10.6) @available(iOS, introduced: 4.0)
public static var propertyListReadStream: CocoaError.Code {
return CocoaError.Code(rawValue: 3842)
}
@available(macOS, introduced: 10.6) @available(iOS, introduced: 4.0)
public static var propertyListWriteStream: CocoaError.Code {
return CocoaError.Code(rawValue: 3851)
}
@available(macOS, introduced: 10.10) @available(iOS, introduced: 8.0)
public static var propertyListWriteInvalid: CocoaError.Code {
return CocoaError.Code(rawValue: 3852)
}
@available(macOS, introduced: 10.8) @available(iOS, introduced: 6.0)
public static var xpcConnectionInterrupted: CocoaError.Code {
return CocoaError.Code(rawValue: 4097)
}
@available(macOS, introduced: 10.8) @available(iOS, introduced: 6.0)
public static var xpcConnectionInvalid: CocoaError.Code {
return CocoaError.Code(rawValue: 4099)
}
@available(macOS, introduced: 10.8) @available(iOS, introduced: 6.0)
public static var xpcConnectionReplyInvalid: CocoaError.Code {
return CocoaError.Code(rawValue: 4101)
}
@available(macOS, introduced: 10.9) @available(iOS, introduced: 7.0)
public static var ubiquitousFileUnavailable: CocoaError.Code {
return CocoaError.Code(rawValue: 4353)
}
@available(macOS, introduced: 10.9) @available(iOS, introduced: 7.0)
public static var ubiquitousFileNotUploadedDueToQuota: CocoaError.Code {
return CocoaError.Code(rawValue: 4354)
}
@available(macOS, introduced: 10.9) @available(iOS, introduced: 7.0)
public static var ubiquitousFileUbiquityServerNotAvailable: CocoaError.Code {
return CocoaError.Code(rawValue: 4355)
}
@available(macOS, introduced: 10.10) @available(iOS, introduced: 8.0)
public static var userActivityHandoffFailed: CocoaError.Code {
return CocoaError.Code(rawValue: 4608)
}
@available(macOS, introduced: 10.10) @available(iOS, introduced: 8.0)
public static var userActivityConnectionUnavailable: CocoaError.Code {
return CocoaError.Code(rawValue: 4609)
}
@available(macOS, introduced: 10.10) @available(iOS, introduced: 8.0)
public static var userActivityRemoteApplicationTimedOut: CocoaError.Code {
return CocoaError.Code(rawValue: 4610)
}
@available(macOS, introduced: 10.10) @available(iOS, introduced: 8.0)
public static var userActivityHandoffUserInfoTooLarge: CocoaError.Code {
return CocoaError.Code(rawValue: 4611)
}
@available(macOS, introduced: 10.11) @available(iOS, introduced: 9.0)
public static var coderReadCorrupt: CocoaError.Code {
return CocoaError.Code(rawValue: 4864)
}
@available(macOS, introduced: 10.11) @available(iOS, introduced: 9.0)
public static var coderValueNotFound: CocoaError.Code {
return CocoaError.Code(rawValue: 4865)
}
public static var coderInvalidValue: CocoaError.Code {
return CocoaError.Code(rawValue: 4866)
}
}
extension CocoaError.Code {
@available(*, deprecated, renamed: "fileNoSuchFile")
public static var fileNoSuchFileError: CocoaError.Code {
return CocoaError.Code(rawValue: 4)
}
@available(*, deprecated, renamed: "fileLocking")
public static var fileLockingError: CocoaError.Code {
return CocoaError.Code(rawValue: 255)
}
@available(*, deprecated, renamed: "fileReadUnknown")
public static var fileReadUnknownError: CocoaError.Code {
return CocoaError.Code(rawValue: 256)
}
@available(*, deprecated, renamed: "fileReadNoPermission")
public static var fileReadNoPermissionError: CocoaError.Code {
return CocoaError.Code(rawValue: 257)
}
@available(*, deprecated, renamed: "fileReadInvalidFileName")
public static var fileReadInvalidFileNameError: CocoaError.Code {
return CocoaError.Code(rawValue: 258)
}
@available(*, deprecated, renamed: "fileReadCorruptFile")
public static var fileReadCorruptFileError: CocoaError.Code {
return CocoaError.Code(rawValue: 259)
}
@available(*, deprecated, renamed: "fileReadNoSuchFile")
public static var fileReadNoSuchFileError: CocoaError.Code {
return CocoaError.Code(rawValue: 260)
}
@available(*, deprecated, renamed: "fileReadInapplicableStringEncoding")
public static var fileReadInapplicableStringEncodingError: CocoaError.Code {
return CocoaError.Code(rawValue: 261)
}
@available(*, deprecated, renamed: "fileReadUnsupportedScheme")
public static var fileReadUnsupportedSchemeError: CocoaError.Code {
return CocoaError.Code(rawValue: 262)
}
@available(macOS, introduced: 10.5) @available(iOS, introduced: 2.0)
@available(*, deprecated, renamed: "fileReadTooLarge")
public static var fileReadTooLargeError: CocoaError.Code {
return CocoaError.Code(rawValue: 263)
}
@available(macOS, introduced: 10.5) @available(iOS, introduced: 2.0)
@available(*, deprecated, renamed: "fileReadUnknownStringEncoding")
public static var fileReadUnknownStringEncodingError: CocoaError.Code {
return CocoaError.Code(rawValue: 264)
}
@available(*, deprecated, renamed: "fileWriteUnknown")
public static var fileWriteUnknownError: CocoaError.Code {
return CocoaError.Code(rawValue: 512)
}
@available(*, deprecated, renamed: "fileWriteNoPermission")
public static var fileWriteNoPermissionError: CocoaError.Code {
return CocoaError.Code(rawValue: 513)
}
@available(*, deprecated, renamed: "fileWriteInvalidFileName")
public static var fileWriteInvalidFileNameError: CocoaError.Code {
return CocoaError.Code(rawValue: 514)
}
@available(macOS, introduced: 10.7) @available(iOS, introduced: 5.0)
@available(*, deprecated, renamed: "fileWriteFileExists")
public static var fileWriteFileExistsError: CocoaError.Code {
return CocoaError.Code(rawValue: 516)
}
@available(*, deprecated, renamed: "fileWriteInapplicableStringEncoding")
public static var fileWriteInapplicableStringEncodingError: CocoaError.Code {
return CocoaError.Code(rawValue: 517)
}
@available(*, deprecated, renamed: "fileWriteUnsupportedScheme")
public static var fileWriteUnsupportedSchemeError: CocoaError.Code {
return CocoaError.Code(rawValue: 518)
}
@available(*, deprecated, renamed: "fileWriteOutOfSpace")
public static var fileWriteOutOfSpaceError: CocoaError.Code {
return CocoaError.Code(rawValue: 640)
}
@available(macOS, introduced: 10.6) @available(iOS, introduced: 4.0)
@available(*, deprecated, renamed: "fileWriteVolumeReadOnly")
public static var fileWriteVolumeReadOnlyError: CocoaError.Code {
return CocoaError.Code(rawValue: 642)
}
@available(macOS, introduced: 10.11) @available(iOS, unavailable)
@available(*, deprecated, renamed: "fileManagerUnmountUnknown")
public static var fileManagerUnmountUnknownError: CocoaError.Code {
return CocoaError.Code(rawValue: 768)
}
@available(macOS, introduced: 10.11) @available(iOS, unavailable)
@available(*, deprecated, renamed: "fileManagerUnmountBusy")
public static var fileManagerUnmountBusyError: CocoaError.Code {
return CocoaError.Code(rawValue: 769)
}
@available(*, deprecated, renamed: "keyValueValidation")
public static var keyValueValidationError: CocoaError.Code {
return CocoaError.Code(rawValue: 1024)
}
@available(*, deprecated, renamed: "formatting")
public static var formattingError: CocoaError.Code {
return CocoaError.Code(rawValue: 2048)
}
@available(*, deprecated, renamed: "userCancelled")
public static var userCancelledError: CocoaError.Code {
return CocoaError.Code(rawValue: 3072)
}
@available(macOS, introduced: 10.8) @available(iOS, introduced: 6.0)
@available(*, deprecated, renamed: "featureUnsupported")
public static var featureUnsupportedError: CocoaError.Code {
return CocoaError.Code(rawValue: 3328)
}
@available(macOS, introduced: 10.5) @available(iOS, introduced: 2.0)
@available(*, deprecated, renamed: "executableNotLoadable")
public static var executableNotLoadableError: CocoaError.Code {
return CocoaError.Code(rawValue: 3584)
}
@available(macOS, introduced: 10.5) @available(iOS, introduced: 2.0)
@available(*, deprecated, renamed: "executableArchitectureMismatch")
public static var executableArchitectureMismatchError: CocoaError.Code {
return CocoaError.Code(rawValue: 3585)
}
@available(macOS, introduced: 10.5) @available(iOS, introduced: 2.0)
@available(*, deprecated, renamed: "executableRuntimeMismatch")
public static var executableRuntimeMismatchError: CocoaError.Code {
return CocoaError.Code(rawValue: 3586)
}
@available(macOS, introduced: 10.5) @available(iOS, introduced: 2.0)
@available(*, deprecated, renamed: "executableLoad")
public static var executableLoadError: CocoaError.Code {
return CocoaError.Code(rawValue: 3587)
}
@available(macOS, introduced: 10.5) @available(iOS, introduced: 2.0)
@available(*, deprecated, renamed: "executableLink")
public static var executableLinkError: CocoaError.Code {
return CocoaError.Code(rawValue: 3588)
}
@available(macOS, introduced: 10.6) @available(iOS, introduced: 4.0)
@available(*, deprecated, renamed: "propertyListReadCorrupt")
public static var propertyListReadCorruptError: CocoaError.Code {
return CocoaError.Code(rawValue: 3840)
}
@available(macOS, introduced: 10.6) @available(iOS, introduced: 4.0)
@available(*, deprecated, renamed: "propertyListReadUnknownVersion")
public static var propertyListReadUnknownVersionError: CocoaError.Code {
return CocoaError.Code(rawValue: 3841)
}
@available(macOS, introduced: 10.6) @available(iOS, introduced: 4.0)
@available(*, deprecated, renamed: "propertyListReadStream")