fix UnboundLocalError: local variable 'message' referenced before assignment