- if len(tokens) == 0:
- self.send_to(connection_id, 'EMPTY COMMAND')
- elif len(tokens) == 1 and tokens[0] == 'INC':
- self.cmd_inc(connection_id)
- elif len(tokens) == 1 and tokens[0] == 'GET_TURN':
- self.cmd_get_turn(connection_id)
- elif len(tokens) >= 1 and tokens[0] == 'ECHO':
- self.cmd_echo(tokens, input_, connection_id)
- elif len(tokens) >= 1 and tokens[0] == 'ALL':
- self.cmd_all(tokens, input_)
- elif len(tokens) >= 1 and tokens[0] == 'FIB':
- # TODO: Should this really block the whole loop?
- self.cmd_fib(tokens, connection_id)
- else:
- self.send_to(connection_id, 'UNKNOWN COMMAND')
+ try:
+ if len(tokens) == 0:
+ self.send_to(connection_id, 'EMPTY COMMAND')
+ elif len(tokens) == 1 and tokens[0] == 'INC':
+ self.cmd_inc(connection_id)
+ elif len(tokens) == 1 and tokens[0] == 'GET_TURN':
+ self.cmd_get_turn(connection_id)
+ elif len(tokens) == 2 and tokens[0] == 'MOVE':
+ self.cmd_move(tokens[1])
+ elif len(tokens) >= 1 and tokens[0] == 'ECHO':
+ self.cmd_echo(tokens, input_, connection_id)
+ elif len(tokens) >= 1 and tokens[0] == 'ALL':
+ self.cmd_all(tokens, input_)
+ elif len(tokens) >= 1 and tokens[0] == 'FIB':
+ # TODO: Should this really block the whole loop?
+ self.cmd_fib(tokens, connection_id)
+ else:
+ self.send_to(connection_id, 'UNKNOWN COMMAND')
+ except ArgumentError as e:
+ self.send_to(connection_id, 'ARGUMENT ERROR: ' + str(e))