Files
swift-mirror/stdlib/public/SDK/AppKit/NSError.swift
Doug Gregor 4fd78234c4 [SE-0112] Retain the underlying NSError in NSCocoaError.
NSCocoaError was capturing only the code of a Cocoa error, making it
basically useless. Instead, capture the entire NSError, the code of
which is tracked by an nested, RawRepresentable type Code. Provide
typed accessors for the common keys in the Cocoa error domain, e.g.,
NSFilePathErrorKey, NSStringEncodingErrorKey, NSUnderlyingErrorKey,
and NSURLErrorKey, to make this type easier to use.

This is specifically an implementation of part (4) of the proposed
solution to SE-0112, which makes NSCocoaError more usable. It also
adds localizedDescription to ErrorProtocol.

However, it also introduces the infrastructure needed for importing
error enumeration types more smoothly, e.g., ErrorCodeProtocol
(underscored for now), the ~= operator for matching error codes, and
so on. In essence, NSCocoaError is the pattern that the importer will
follow.
2016-07-12 10:53:52 -07:00

113 lines
4.3 KiB
Swift

extension NSCocoaError.Code {
public static var textReadInapplicableDocumentTypeError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 65806)
}
public static var textWriteInapplicableDocumentTypeError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66062)
}
public static var serviceApplicationNotFoundError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66560)
}
public static var serviceApplicationLaunchFailedError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66561)
}
public static var serviceRequestTimedOutError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66562)
}
public static var serviceInvalidPasteboardDataError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66563)
}
public static var serviceMalformedServiceDictionaryError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66564)
}
public static var serviceMiscellaneousError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66800)
}
public static var sharingServiceNotConfiguredError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 67072)
}
}
extension NSCocoaError {
public static var textReadInapplicableDocumentTypeError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 65806)
}
public static var textWriteInapplicableDocumentTypeError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66062)
}
public static var serviceApplicationNotFoundError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66560)
}
public static var serviceApplicationLaunchFailedError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66561)
}
public static var serviceRequestTimedOutError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66562)
}
public static var serviceInvalidPasteboardDataError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66563)
}
public static var serviceMalformedServiceDictionaryError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66564)
}
public static var serviceMiscellaneousError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66800)
}
public static var sharingServiceNotConfiguredError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 67072)
}
}
extension NSCocoaError {
public var isServiceError: Bool {
return code.rawValue >= 66560 && code.rawValue <= 66817
}
public var isSharingServiceError: Bool {
return code.rawValue >= 67072 && code.rawValue <= 67327
}
public var isTextReadWriteError: Bool {
return code.rawValue >= 65792 && code.rawValue <= 66303
}
}
extension NSCocoaError.Code {
@swift3_migration(renamed: "textReadInapplicableDocumentTypeError")
public static var TextReadInapplicableDocumentTypeError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 65806)
}
@swift3_migration(renamed: "textWriteInapplicableDocumentTypeError")
public static var TextWriteInapplicableDocumentTypeError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66062)
}
@swift3_migration(renamed: "serviceApplicationNotFoundError")
public static var ServiceApplicationNotFoundError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66560)
}
@swift3_migration(renamed: "serviceApplicationLaunchFailedError")
public static var ServiceApplicationLaunchFailedError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66561)
}
@swift3_migration(renamed: "serviceRequestTimedOutError")
public static var ServiceRequestTimedOutError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66562)
}
@swift3_migration(renamed: "serviceInvalidPasteboardDataError")
public static var ServiceInvalidPasteboardDataError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66563)
}
@swift3_migration(renamed: "serviceMalformedServiceDictionaryError")
public static var ServiceMalformedServiceDictionaryError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66564)
}
@swift3_migration(renamed: "serviceMiscellaneousError")
public static var ServiceMiscellaneousError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 66800)
}
@swift3_migration(renamed: "sharingServiceNotConfiguredError")
public static var SharingServiceNotConfiguredError: NSCocoaError.Code {
return NSCocoaError.Code(rawValue: 67072)
}
}