swift
Swift Foundation Error Codes
Common error codes from Swift's Foundation framework error domains, including URLError (NSURLErrorDomain) for network and URL loading failures, CocoaError (NSCocoaErrorDomain) for file system and data operations, and POSIXError for POSIX-level system errors surfaced in Swift contexts.
75 codes
references developer.apple.com/documentation/foundation/urlerrordeveloper.apple.com/documentation/foundation/cocoaerrordeveloper.apple.com/documentation/foundation/posixerror
· All codes 75 codes
- backgroundSessionInUseByAnotherProcess backgroundSessionInUseByAnotherProcess A background URLSession with the given identifier already exists in another process. Background session identifiers must be unique across all processes using the same app group.
- backgroundSessionRequiresSharedContainer backgroundSessionRequiresSharedContainer A background URLSession was created in an app extension but the shared container identifier was not set. Background sessions in extensions must use a shared app group container.
- backgroundSessionWasDisconnected backgroundSessionWasDisconnected The app was disconnected from its background URLSession while tasks were still running. The session's delegate must reconnect to the session to receive completion events when the app relaunches.
- badServerResponse badServerResponse The server returned a response that could not be parsed as a valid HTTP response. Indicates a protocol-level error rather than an application-level error status code.
- badURL badURL The URL passed to the URL loading system is malformed or cannot be parsed. Typically indicates a programming error such as an invalid URL string that was not validated before use.
- callIsActive callIsActive A network request could not be completed because a phone call is currently active and the cellular data connection is unavailable during the call on certain carrier configurations.
- cancelled cancelled The URL loading task was explicitly cancelled, typically by calling cancel() on the URLSessionTask. Also raised when a background session is invalidated while tasks are in flight.
- cannotCloseFile cannotCloseFile The URL loading system could not close the file after completing a download operation. The download data may still be usable but the file descriptor could not be cleanly released.
- cannotConnectToHost cannotConnectToHost A TCP connection to the specified host could not be established. The host may be refusing connections on the requested port or a firewall may be blocking the connection.
- cannotCreateFile cannotCreateFile The URL loading system could not create the file needed to store a downloaded resource. Typically indicates a permissions problem or insufficient disk space at the download destination.
- cannotDecodeContentData cannotDecodeContentData The content data returned by the server could not be decoded using the declared content encoding or character set. The raw data was received but is not interpretable as the declared format.
- cannotDecodeRawData cannotDecodeRawData The content encoding of the response data could not be decoded. Raised when the server declares a Content-Encoding that the URL loading system does not understand or cannot apply.
- cannotFindHost cannotFindHost The host name in the URL could not be resolved to an IP address via DNS. Indicates either an incorrect hostname or a DNS failure.
- cannotLoadFromNetwork cannotLoadFromNetwork The requested resource must be loaded from the network but the request's cache policy disallows network access. Raised when NSURLRequestReturnCacheDataDontLoad is used and no cached data is available.
- cannotMoveFile cannotMoveFile A downloaded file could not be moved from its temporary location to the destination path provided by the URLSession delegate. Check that the destination directory exists and the process has write permission.
- cannotOpenFile cannotOpenFile The URL loading system could not open the file to be uploaded or the temporary file storing a download. The file may have been deleted or the process may lack read permission.
- cannotParseResponse cannotParseResponse The URL loading system received a response that it could not parse into an HTTPURLResponse or other expected response object. Indicates a structural problem with the server's response.
- cannotRemoveFile cannotRemoveFile A downloaded file could not be removed from its temporary location after the download task completed. May leave orphaned temporary files that need manual cleanup.
- cannotWriteToFile cannotWriteToFile The URL loading system could not write data to the file during a download. Can occur when the storage device becomes full or read-only mid-download.
- clientCertificateRejected clientCertificateRejected The client certificate presented during mutual TLS authentication was rejected by the server. The certificate may be expired, revoked, or not accepted by the server's trust policy.
- clientCertificateRequired clientCertificateRequired The server requires a client certificate for mutual TLS authentication and none was provided. The delegate must respond to the authentication challenge with an appropriate client identity.
- coderInvalidValue coderInvalidValue An encoder was asked to encode a value that is invalid or not supported by the archive format. Raised when trying to encode non-property-list types with NSKeyedArchiver without a custom encoding strategy.
- coderReadCorrupt coderReadCorrupt Data being decoded by NSCoder (or a Swift Codable decoder) is corrupt and cannot be deserialised. Raised by NSKeyedUnarchiver and similar when the archive format is invalid or the data has been truncated.
- coderValueNotFound coderValueNotFound A value expected by the decoder was not present in the archive. Raised by NSKeyedUnarchiver when a required key is missing, often due to a schema change between the archiving and unarchiving code versions.
- dataNotAllowed dataNotAllowed The cellular data connection is not permitted for this request because the user has restricted cellular data usage for the app, or cellular data is turned off entirely on the device.
- dnsLookupFailed dnsLookupFailed The DNS lookup for the host name failed. Differs from cannotFindHost in that the DNS query was sent but returned an error response rather than no answer.
- downloadDecodingFailedMidStream downloadDecodingFailedMidStream The decoding of a download task's data failed partway through the transfer. Indicates that the data stream became corrupt or undecodable after initially successful decoding.
- downloadDecodingFailedToComplete downloadDecodingFailedToComplete The decoding of a download task's data failed upon completion of the transfer. The full data was received but could not be decoded into the expected format.
- executableArchitectureMismatch executableArchitectureMismatch The executable does not contain code for the current processor architecture. Raised when loading a bundle or plug-in compiled only for a different architecture, such as x86_64 on an Apple Silicon device without Rosetta.
- executableLoad executableLoad A general error occurred while loading the executable or bundle. Raised when dlopen or the bundle loading mechanism fails for a reason not covered by a more specific executable error code.
- executableNotLoadable executableNotLoadable The executable or bundle could not be loaded. Raised by Bundle when attempting to load a plug-in or dynamic framework that cannot be initialised by the runtime.
- executableRuntimeMismatch executableRuntimeMismatch The executable requires a runtime environment that is incompatible with the current system. Raised when a plug-in was built against an SDK or Objective-C runtime version that does not match the host process.
- fileLocking fileLocking A file lock could not be acquired or released. Raised when a file locking operation fails, for example when NSFileManager attempts to lock a file that is already locked by another process.
- fileManagerUnmountBusy fileManagerUnmountBusy A volume could not be unmounted because it is still in use by one or more processes. The caller should close any open file handles to the volume before retrying the unmount.
- fileNoSuchFile fileNoSuchFile The file or directory at the specified path does not exist. Raised by Foundation file-system operations such as FileManager methods and NSData initialisation from a file URL when the path cannot be found.
- fileReadCorruptFile fileReadCorruptFile The file data is corrupt and cannot be read or deserialised. Raised by APIs like PropertyListSerialization or JSONSerialization when the file contents do not conform to the expected format.
- fileReadInapplicableStringEncoding fileReadInapplicableStringEncoding The file's content could not be read using the specified string encoding. Raised by String initialisation from a file URL when the file bytes are not valid for the requested encoding such as UTF-8.
- fileReadInvalidFileName fileReadInvalidFileName The file name or path contains characters that are invalid for the file system. Raised when attempting to open or read a file whose path cannot be represented on the underlying file system.
- fileReadNoPermission fileReadNoPermission The process does not have permission to read the file at the specified path. Check the file's POSIX permissions and any App Sandbox entitlements that may restrict file access.
- fileReadNoSuchFile fileReadNoSuchFile The file to be read does not exist at the given path. This is the read-specific counterpart to fileNoSuchFile and is raised by file-reading APIs in Foundation when the source file is missing.
- fileReadUnknown fileReadUnknown An unknown error occurred while reading a file. Used as a catch-all for file read failures that do not map to a more specific CocoaError code.
- fileReadUnsupportedScheme fileReadUnsupportedScheme The URL scheme used in a file-reading operation is not supported. Foundation file APIs operate on file:// URLs and will raise this error when given a URL with an unsupported scheme.
- fileWriteFileExists fileWriteFileExists A file already exists at the destination path and the operation was not configured to overwrite it. Raised by FileManager copy and move operations when the withoutOverwriting option is in effect.
- fileWriteInapplicableStringEncoding fileWriteInapplicableStringEncoding The string could not be converted to the specified encoding for writing to a file. Raised when characters in the string cannot be represented in the target encoding, such as writing emoji to an ASCII file.
- fileWriteInvalidFileName fileWriteInvalidFileName The proposed file name is invalid for the target file system. Raised when writing a file whose name contains characters not permitted by the file system, or when the name exceeds the maximum length.
- fileWriteNoPermission fileWriteNoPermission The process does not have permission to write to the file or directory at the specified path. Check file system permissions and App Sandbox entitlements for the target location.
- fileWriteOutOfSpace fileWriteOutOfSpace There is insufficient space on the volume to complete the write operation. Raised by file-writing APIs when the disk or storage volume does not have enough free space to store the data.
- fileWriteUnknown fileWriteUnknown An unknown error occurred while writing a file. Used as a catch-all for file write failures that do not map to a more specific CocoaError code.
- fileWriteVolumeReadOnly fileWriteVolumeReadOnly The volume on which the target file resides is mounted read-only. Raised when attempting to create, modify, or delete files on a read-only volume such as a disc image or system volume.
- formattingError formattingError A formatting operation failed, such as when a Formatter subclass cannot convert a value to or from its string representation. Raised by NSFormatter and its subclasses including DateFormatter and NumberFormatter.
- internationalRoamingOff internationalRoamingOff The request requires a network connection but international data roaming is disabled on the device. The user must enable roaming or connect to a local network to proceed.
- keyValueValidation keyValueValidation A key-value coding validation failure occurred. Raised by NSManagedObject or other KVC-compliant classes when validateValue(_:forKey:) determines that the value violates a validation constraint.
- networkConnectionLost networkConnectionLost The network connection was dropped while the request was in progress. Common on mobile devices when transitioning between networks or entering areas with poor signal.
- notConnectedToInternet notConnectedToInternet The device has no active internet connection. Raised by URLSession when a request cannot be sent because the network interface is offline.
- propertyListReadCorrupt propertyListReadCorrupt The property list data is malformed and cannot be parsed. Raised by PropertyListSerialization when the input data does not conform to any valid property list format (XML, binary, or OpenStep).
- propertyListReadStream propertyListReadStream The property list could not be read from the input stream. Raised when the stream provides insufficient or invalid data during a streaming property list read operation.
- propertyListReadUnknownVersion propertyListReadUnknownVersion The property list data uses a format version that is not recognised by the current runtime. Typically encountered when reading binary property lists created by a newer OS version.
- propertyListWriteInvalid propertyListWriteInvalid The object graph to be serialised contains values that are not valid property list types. Valid property list types are NSString, NSData, NSDate, NSNumber, NSArray, and NSDictionary.
- propertyListWriteStream propertyListWriteStream The property list could not be written to the output stream. Raised when the stream becomes full or encounters an error while a streaming property list write operation is in progress.
- redirectToNonExistentLocation redirectToNonExistentLocation A redirect was received pointing to a location that does not exist or cannot be contacted. Occurs when a server issues a redirect with a malformed or unreachable Location header.
- requestBodyStreamExhausted requestBodyStreamExhausted The body stream of the URLRequest was read to completion before the upload could be sent. This can occur when a stream is not rewindable and the system needs to retry the request after an authentication challenge.
- resourceUnavailable resourceUnavailable The requested resource could not be loaded because it is not available. The server acknowledged the request but indicated the resource cannot be served at this time.
- secureConnectionFailed secureConnectionFailed The SSL/TLS handshake failed and a secure connection could not be established. Can be caused by incompatible protocol versions, cipher suite mismatches, or certificate validation failures not covered by a more specific error code.
- serverCertificateHasBadDate serverCertificateHasBadDate The server's SSL/TLS certificate has an invalid or expired validity period. The system rejects the connection to protect against presenting stale or misconfigured certificates.
- serverCertificateHasUnknownRoot serverCertificateHasUnknownRoot The certificate chain for the server's SSL/TLS certificate terminates at a root certificate not recognised by the system. Similar to serverCertificateUntrusted but specifically indicates an unknown root CA.
- serverCertificateNotYetValid serverCertificateNotYetValid The server's SSL/TLS certificate has a notBefore date in the future, meaning it is not yet valid. This often indicates a clock skew issue on either the client or the server.
- serverCertificateUntrusted serverCertificateUntrusted The server's SSL/TLS certificate was issued by an authority not trusted by the system. Commonly encountered with self-signed certificates or custom CAs not installed in the trust store.
- timedOut timedOut The request exceeded the allowed time interval before a response was received. The timeout interval is configured via URLRequest.timeoutInterval.
- unsupportedURL unsupportedURL The URL scheme is not supported by the URL loading system. For example, passing a URL with a custom scheme that has no registered handler, or a scheme unsupported by URLSession such as ftp in newer OS versions.
- userActivityConnectionUnavailable userActivityConnectionUnavailable A Handoff activity could not be continued because the required network connection between devices is unavailable. Both devices must be on the same network or have Bluetooth connectivity.
- userActivityHandoffFailed userActivityHandoffFailed A Handoff activity could not be continued on the receiving device. Raised when the target app is available but the NSUserActivity data cannot be transferred or decoded successfully.
- userActivityHandoffUserInfoTooLarge userActivityHandoffUserInfoTooLarge The userInfo dictionary of the NSUserActivity is too large to be transferred via Handoff. Reduce the amount of data stored in userInfo or use transferring streams for large payloads.
- userActivityRemoteApplicationTimedOut userActivityRemoteApplicationTimedOut The remote application did not respond to the Handoff continuation request within the required time limit. The source app may have been suspended or terminated before the handoff completed.
- userAuthenticationRequired userAuthenticationRequired The resource requires authentication and no credentials were provided, or the provided credentials were rejected. The URLSession delegate can supply credentials via URLAuthenticationChallenge.
- userCancelledAuthentication userCancelledAuthentication The authentication challenge was presented to the user and the user chose to cancel rather than supply credentials. Results in the request failing without retrying.