Repository: apple/swift-nio
File: Sources/NIOFileSystem/FileSystemError+Syscall.swift (Swift)

Code before:
        case .tooManyOpenFiles:
            code = .unavailable
            message = """
                Unable to open the source ('\(sourcePath)') or destination ('\(destinationPath)') files, \
                too many file descriptors are open.
                """
        case .noSuchFileOrDirectory:
            code = .notFound
            message = """
                Unable to open or create file at path '\(sourcePath)', either a component of the \
                path did not exist or the named file to be opened did not exist.
                """
        default:
            code = .unknown
            message = "Can't copy file from '\(sourcePath)' to '\(destinationPath)'."
        }

        return FileSystemError(
            code: code,
            message: message,
            systemCall: "fcopyfile",
            errno: errno,
            location: location
        )
    }

    @_spi(Testing)
    public static func sendfile(
        errno: Errno,
        from sourcePath: FilePath,
        to destinationPath: FilePath,
        location: SourceLocation
    ) -> FileSystemError {
        let code: FileSystemError.Code
        let message: String

        switch errno {
        case .ioError:
            code = .io
            message = """
                An I/O error occurred while reading from '\(sourcePath)', can't copy to \
                '\(destinationPath)'.
                """
        case .noMemory:
            code = .io
            message = """
                Insufficient memory to read from '\(sourcePath)', can't copy to \
                '\(destinationPath)'.
                """
        default:
            code = .unknown

Review comment (suggestion):
Can you update the error tests? They check that `errno`s get mapped to an appropriate file system error code.

Code after:
        location: SourceLocation
    ) -> Self {
        let code: Code
        let message: String

        switch errno {
        case .notSupported:
            code = .invalidArgument
            message = """
                Can't copy file from '\(sourcePath)' to '\(destinationPath)', the item to copy is \
                not a directory, symbolic link or regular file.
                """
        case .permissionDenied:
            code = .permissionDenied
            message = """
                Can't copy file, search permission was denied for a component of the path \
                prefix for the source ('\(sourcePath)') or destination ('\(destinationPath)'), \
                or write permission was denied for a component of the path prefix for the source.
                """
        case .invalidArgument:
            code = .invalidArgument
            message = """
                Can't copy file from '\(sourcePath)' to '\(destinationPath)', the destination \
                path already exists.
                """
        case .fileExists:
            code = .fileAlreadyExists
            message = """
                Unable to create file at path '\(destinationPath)', no existing file options were set \
                which implies that no file should exist but a file already exists at the \
                specified path.
                """
        case .tooManyOpenFiles:
            code = .unavailable
            message = """
                Unable to open the source ('\(sourcePath)') or destination ('\(destinationPath)') files, \
                too many file descriptors are open.
                """
        case .noSuchFileOrDirectory:
            code = .notFound
            message = """
                Unable to open or create file at path '\(sourcePath)', either a component of the \
                path did not exist or the named file to be opened did not exist.
                """
        default:
            code = .unknown
            message = "Can't copy file from '\(sourcePath)' to '\(destinationPath)'."
        }

        return FileSystemError(
            code: code,