Exemple #1
0
 def _execute_request_err_callback(self, msg_id, exc):
     """Error callback used for coroutine request message."""
     exc_info = (type(exc), exc, None)
     error = JsonRpcInternalError.of(exc_info).to_dict()
     logger.exception('Exception occurred for message "%s": %s', msg_id,
                      error)
     self._send_response(msg_id, error=error)
Exemple #2
0
    def _execute_notification_callback(self, future):
        """Success callback used for coroutine notification message."""
        if future.exception():

            try:
                raise future.exception()
            except Exception:
                error = JsonRpcInternalError.of(sys.exc_info()).to_dict()
                logger.exception('Exception occurred in notification: "%s"', error)
Exemple #3
0
    def _check_ret_type_and_send_response(self, method_name, method_type, msg_id, result):
        """Check if registered feature returns appropriate result type."""
        if method_type == ATTR_FEATURE_TYPE:
            return_type = get_method_return_type(method_name)
            if not is_instance(result, return_type):
                error = JsonRpcInternalError().to_dict()
                self._send_response(msg_id, error=error)

        self._send_response(msg_id, result=result)
Exemple #4
0
 def _execute_request_callback(self, method_name, method_type, msg_id, future):
     """Success callback used for coroutine request message."""
     try:
         if not future.cancelled():
             self._check_ret_type_and_send_response(
                 method_name, method_type, msg_id, result=future.result())
         else:
             self._send_response(
                 msg_id,
                 error=JsonRpcRequestCancelled(f'Request with id "{msg_id}" is canceled')
             )
         self._client_request_futures.pop(msg_id, None)
     except Exception:
         error = JsonRpcInternalError.of(sys.exc_info()).to_dict()
         logger.exception('Exception occurred for message "%s": %s', msg_id, error)
         self._send_response(msg_id, error=error)
Exemple #5
0
    def _handle_request(self, msg_id, method_name, params):
        """Handles a request from the client."""
        try:
            handler = self._get_handler(method_name)

            # workspace/executeCommand is a special case
            if method_name == WORKSPACE_EXECUTE_COMMAND:
                handler(params, msg_id)
            else:
                self._execute_request(msg_id, handler, params)

        except JsonRpcException as e:
            logger.exception('Failed to handle request %s %s %s', msg_id, method_name, params)
            self._send_response(msg_id, None, e.to_dict())
        except Exception:
            logger.exception('Failed to handle request %s %s %s', msg_id, method_name, params)
            err = JsonRpcInternalError.of(sys.exc_info()).to_dict()
            self._send_response(msg_id, None, err)