I think the unix side is actually wrong and there should be a precondition there as well, according to https://developer.apple.com/documentation/foundation/filehandle/1410936-write "This method raises an exception if the file descriptor is closed or is not valid "