def convert_to_dbexception(self, args): """Converts from a VitessError to the appropriate dbexceptions class. Args: args: argument tuple to use to create the new exception. Returns: An exception from dbexceptions. """ # FIXME(alainjobart): this is extremely confusing: self.message is only # used for integrity errors, and nothing else. The other cases # have to provide the message in the args. if self.code == vtrpc_pb2.UNAVAILABLE: if throttler_err_re.search(self.message): return dbexceptions.ThrottledError(args) return dbexceptions.TransientError(args) if self.code == vtrpc_pb2.FAILED_PRECONDITION: return dbexceptions.QueryNotServed(args) if self.code == vtrpc_pb2.ALREADY_EXISTS: # Prune the error message to truncate after the mysql errno, since # the error message may contain the query string with bind variables. msg = self.message.lower() parts = self._errno_pattern.split(msg) pruned_msg = msg[:msg.find(parts[2])] new_args = (pruned_msg, ) + tuple(args[1:]) return dbexceptions.IntegrityError(new_args) if self.code == vtrpc_pb2.INVALID_ARGUMENT: return dbexceptions.ProgrammingError(args) return dbexceptions.DatabaseError(args)
def handle_app_error(exc_args): msg = str(exc_args[0]).lower() # Operational Error if msg.startswith('retry'): return dbexceptions.RetryError(exc_args) if msg.startswith('fatal'): return dbexceptions.FatalError(exc_args) if msg.startswith('tx_pool_full'): return dbexceptions.TxPoolFull(exc_args) # Integrity and Database Error match = _errno_pattern.search(msg) if match: # Prune the error message to truncate after the mysql errno, since # the error message may contain the query string with bind variables. mysql_errno = int(match.group(1)) if mysql_errno == 1062: parts = _errno_pattern.split(msg) pruned_msg = msg[:msg.find(parts[2])] new_args = (pruned_msg, ) + tuple(exc_args[1:]) return dbexceptions.IntegrityError(new_args) # TODO(sougou/liguo): remove this case once servers are deployed elif mysql_errno == 1290 and 'read-only' in msg: return dbexceptions.RetryError(exc_args) return dbexceptions.DatabaseError(exc_args)
def convert_to_dbexception(self, args): """Converts from a TabletError to the appropriate dbexceptions class. Args: args: argument tuple to use to create the new exception. Returns: An exception from dbexceptions. """ if self.code == vtrpc_pb2.QUERY_NOT_SERVED: return dbexceptions.RetryError(args) if self.code == vtrpc_pb2.INTERNAL_ERROR: return dbexceptions.FatalError(args) if self.code == vtrpc_pb2.RESOURCE_EXHAUSTED: return dbexceptions.TxPoolFull(args) if self.code == vtrpc_pb2.INTEGRITY_ERROR: # Prune the error message to truncate after the mysql errno, since # the error message may contain the query string with bind variables. msg = self.message.lower() parts = self._errno_pattern.split(msg) pruned_msg = msg[:msg.find(parts[2])] new_args = (pruned_msg,) + tuple(args[1:]) return dbexceptions.IntegrityError(new_args) return dbexceptions.DatabaseError(args)
def convert_exception(exc, *args): new_args = exc.args + args if isinstance(exc, gorpc.TimeoutError): return dbexceptions.TimeoutError(new_args) elif isinstance(exc, gorpc.AppError): msg = str(exc[0]).lower() if msg.startswith('retry'): return dbexceptions.RetryError(new_args) if msg.startswith('fatal'): return dbexceptions.FatalError(new_args) if msg.startswith('tx_pool_full'): return dbexceptions.TxPoolFull(new_args) match = _errno_pattern.search(msg) if match: mysql_errno = int(match.group(1)) if mysql_errno == 1062: return dbexceptions.IntegrityError(new_args) # TODO(sougou/liguo): remove this case once servers are deployed elif mysql_errno == 1290 and 'read-only' in msg: return dbexceptions.RetryError(new_args) return dbexceptions.DatabaseError(new_args) elif isinstance(exc, gorpc.ProgrammingError): return dbexceptions.ProgrammingError(new_args) elif isinstance(exc, gorpc.GoRpcError): return dbexceptions.FatalError(new_args) return exc
def handle_app_error(exc_args): msg = str(exc_args[0]).lower() if msg.startswith('request_backlog'): return dbexceptions.RequestBacklog(exc_args) match = _errno_pattern.search(msg) if match: mysql_errno = int(match.group(1)) # Prune the error message to truncate the query string # returned by mysql as it contains bind variables. if mysql_errno == 1062: parts = _errno_pattern.split(msg) pruned_msg = msg[:msg.find(parts[2])] new_args = (pruned_msg, ) + tuple(exc_args[1:]) return dbexceptions.IntegrityError(new_args) return dbexceptions.DatabaseError(exc_args)
def convert_exception(exc, *args): new_args = exc.args + args vtdb_logger.get_logger().vtgatev2_exception(exc) if isinstance(exc, gorpc.TimeoutError): return dbexceptions.TimeoutError(new_args) elif isinstance(exc, gorpc.AppError): msg = str(exc[0]).lower() match = _errno_pattern.search(msg) if match: mysql_errno = int(match.group(1)) if mysql_errno == 1062: return dbexceptions.IntegrityError(new_args) return dbexceptions.DatabaseError(new_args) elif isinstance(exc, gorpc.ProgrammingError): return dbexceptions.ProgrammingError(new_args) elif isinstance(exc, gorpc.GoRpcError): return dbexceptions.FatalError(new_args) return exc
def convert_exception(exc, *args): new_args = exc.args + args if isinstance(exc, gorpc.TimeoutError): return dbexceptions.TimeoutError(new_args) elif isinstance(exc, gorpc.AppError): msg = str(exc[0]).lower() if msg.startswith('request_backlog'): return dbexceptions.RequestBacklog(new_args) match = _errno_pattern.search(msg) if match: mysql_errno = int(match.group(1)) if mysql_errno == 1062: return dbexceptions.IntegrityError(new_args) return dbexceptions.DatabaseError(new_args) elif isinstance(exc, gorpc.ProgrammingError): return dbexceptions.ProgrammingError(new_args) elif isinstance(exc, gorpc.GoRpcError): return dbexceptions.FatalError(new_args) return exc
def convert_to_dbexception(self, args): """Converts from a VitessError to the appropriate dbexceptions class. Args: args: argument tuple to use to create the new exception. Returns: An exception from dbexceptions. """ # FIXME(alainjobart): this is extremely confusing: self.message is only # used for integrity errors, and nothing else. The other cases # have to provide the message in the args. if self.code == vtrpc_pb2.TRANSIENT_ERROR: return dbexceptions.TransientError(args) if self.code == vtrpc_pb2.INTEGRITY_ERROR: # Prune the error message to truncate after the mysql errno, since # the error message may contain the query string with bind variables. msg = self.message.lower() parts = self._errno_pattern.split(msg) pruned_msg = msg[:msg.find(parts[2])] new_args = (pruned_msg, ) + tuple(args[1:]) return dbexceptions.IntegrityError(new_args) return dbexceptions.DatabaseError(args)
def _prune_integrity_error(msg, exc_args): """Prunes an integrity error message and returns an IntegrityError.""" parts = _errno_pattern.split(msg) pruned_msg = msg[:msg.find(parts[2])] exc_args = (pruned_msg,) + tuple(exc_args[1:]) return dbexceptions.IntegrityError(exc_args)