+ peer_count = len(list(set(self.peers_with_shares)))
+ # If peer_count < needed_shares, then the second error
+ # message is nonsensical, so we use this one.
+ if peer_count < self.needed_shares:
+ msg = ("shares could only be placed or found on %d "
+ "server(s). "
+ "We were asked to place shares on at least %d "
+ "server(s) such that any %d of them have "
+ "enough shares to recover the file." %
+ (peer_count,
+ self.servers_of_happiness,
+ self.needed_shares))
+ # Otherwise, if we've placed on at least needed_shares
+ # peers, but there isn't an x-happy subset of those peers
+ # for x < needed_shares, we use this error message.
+ elif len(effective_happiness) < self.needed_shares:
+ msg = ("shares could be placed or found on %d "
+ "server(s), but they are not spread out evenly "
+ "enough to ensure that any %d of these servers "
+ "would have enough shares to recover the file. "
+ "We were asked to place "
+ "shares on at least %d servers such that any "
+ "%d of them have enough shares to recover the "
+ "file." %
+ (peer_count,
+ self.needed_shares,
+ self.servers_of_happiness,
+ self.needed_shares))
+ # Otherwise, if there is an x-happy subset of peers where
+ # x >= needed_shares, but x < shares_of_happiness, then
+ # we use this message.
+ else:
+ msg = ("shares could only be placed on %d server(s) "
+ "such that any %d of them have enough shares "
+ "to recover the file, but we were asked to use "
+ "at least %d such servers." %
+ (len(effective_happiness),
+ self.needed_shares,
+ self.servers_of_happiness))
+ raise UploadUnhappinessError(msg)