Sarven rescue - code problem or bug i dont now

its tell me an error problem in the bold place

# Rescue the peasant from the bandits and return her to the village.
# Choose the path that suits you, avoiding patrols or facing them head on.
# Potions will grant random effects–some good, some bad.
# Feeling brave? Bonus if you can loot the ogre treasure chest.
enemy = self.findNearest(self.findEnemies())
**while self.distanceTo(self.findNearest(self.findEnemies())) > 10:**
    enemy = self.findNearest(self.findEnemies())
self.cleave(self.findNearest(self.findEnemies()))
self.moveXY(115, 12)
enemy = self.findNearest(self.findEnemies())
while enemy :
    enemy = self.findNearest(self.findEnemies())
    if self.isReady("cleave") :
        self.cleave(enemy)
    else :
        if self.isReady("bash") :
            self.bash(enemy)
        else :
            self.attack(enemy)
self.moveXY(12, 12)

i think there may be the same problem as often. what if “no enemy” is there? He cant get the distance to “null” try this…