make typeerrors give more accurate and clearer errors

This commit is contained in:
rasmus 2020-12-23 04:28:35 +02:00
parent 830db7f051
commit 37f9aa76be
2 changed files with 5 additions and 5 deletions

View File

@ -3,11 +3,11 @@ import logging
def listServers(serverName):
# Input validation
if not type(serverName) is list:
raise TypeError("ssh_runcmd: command must be a list, '" + str(serverName) + "' is not.")
raise TypeError("listServers: serverName must be a list, '" + str(serverName) + "' is not.")
# Check if the first item in the list is the header. If this is true (data started at right place), most likely the other data is fine as well.
if not serverName[0] == 'Bay Server Name Serial Number Status Power UID Partner\r':
logging.critical(serverName)
raise ValueError('Unexpected data recieved while listing servers.')
raise ValueError('listServers: Unexpected data recieved.')
serverNamePos = [] # Init list

View File

@ -3,11 +3,11 @@ import logging
def relativeUsage(encPowerUsageAC, baysInUseCount, servers):
# Input validation
if not type(encPowerUsageAC) is int:
raise TypeError("ssh_runcmd: command must be an integer, '" + str(encPowerUsageAC) + "' is not.")
raise TypeError("relativeUsage: command must be an integer, '" + str(encPowerUsageAC) + "' is not.")
if not type(baysInUseCount) is int:
raise TypeError("ssh_runcmd: command must be an integer, '" + str(baysInUseCount) + "' is not.")
raise TypeError("relativeUsage: command must be an integer, '" + str(baysInUseCount) + "' is not.")
if not type(servers) is list:
raise TypeError("ssh_runcmd: command must be a list, '" + str(servers) + "' is not.")
raise TypeError("relativeUsage: command must be a list, '" + str(servers) + "' is not.")
# Add up the total DC usage of blades.
absoluteBladesUsage = 0