mirror of
https://github.com/facebook/squangle.git
synced 2025-04-19 09:42:18 +03:00
Remove mustSucceed()
function and RequiredOperationFailedException
Summary: The `mustSucceed()` function is dangerous. It was intended as a shortcut during testing, but there are other ways to do that. Remove it so that it won't be used in production code accidentally. The RequiredOperationFailedException was generated to be thrown by this function so remove it (at least as a globally available exception) as well. Reviewed By: tensor-flower Differential Revision: D72977621 fbshipit-source-id: 8162592d8761acbbb7391d167f19f2bc043ae6b1
This commit is contained in:
parent
faee52e110
commit
5ff62ec2be
@ -6,18 +6,12 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#ifndef COMMON_DB_EXCEPTION_UTIL_H
|
||||
#define COMMON_DB_EXCEPTION_UTIL_H
|
||||
#pragma once
|
||||
|
||||
#include <folly/CPortability.h>
|
||||
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "squangle/base/Base.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace db {
|
||||
namespace facebook::db {
|
||||
|
||||
class FOLLY_EXPORT Exception : public std::runtime_error {
|
||||
public:
|
||||
@ -34,11 +28,4 @@ class FOLLY_EXPORT InvalidConnectionException : public Exception {
|
||||
using Exception::Exception;
|
||||
};
|
||||
|
||||
class FOLLY_EXPORT RequiredOperationFailedException : public Exception {
|
||||
public:
|
||||
using Exception::Exception;
|
||||
};
|
||||
} // namespace db
|
||||
} // namespace facebook
|
||||
|
||||
#endif
|
||||
} // namespace facebook::db
|
||||
|
@ -183,14 +183,6 @@ ConnectionHolder* ConnectOperationImpl::mysqlConnection() const {
|
||||
return folly::join(" ", parts);
|
||||
}
|
||||
|
||||
void ConnectOperation::mustSucceed() {
|
||||
run().wait();
|
||||
if (!ok()) {
|
||||
throw db::RequiredOperationFailedException(
|
||||
"Connect failed: " + mysql_error());
|
||||
}
|
||||
}
|
||||
|
||||
/*static*/
|
||||
std::shared_ptr<ConnectOperation> ConnectOperation::create(
|
||||
std::unique_ptr<ConnectOperationImpl> impl) {
|
||||
|
@ -316,8 +316,6 @@ class ConnectOperation : public Operation {
|
||||
}
|
||||
}
|
||||
|
||||
void mustSucceed() override;
|
||||
|
||||
bool isActive() const {
|
||||
return impl()->isActive();
|
||||
}
|
||||
|
@ -174,14 +174,6 @@ FetchOperation& FetchOperationImpl::getOp() const {
|
||||
return *(FetchOperation*)op_;
|
||||
}
|
||||
|
||||
void FetchOperation::mustSucceed() {
|
||||
run().wait();
|
||||
if (!ok()) {
|
||||
throw db::RequiredOperationFailedException(
|
||||
"Query failed: " + mysql_error());
|
||||
}
|
||||
}
|
||||
|
||||
folly::StringPiece FetchOperationImpl::toString(FetchAction action) {
|
||||
switch (action) {
|
||||
case FetchAction::StartQuery:
|
||||
|
@ -250,8 +250,6 @@ class FetchOperation : public Operation {
|
||||
public:
|
||||
using RespAttrs = AttributeMap;
|
||||
|
||||
void mustSucceed() override;
|
||||
|
||||
// Number of queries that succeed to execute
|
||||
int numQueriesExecuted() const {
|
||||
return impl_->numQueriesExecuted();
|
||||
|
@ -492,10 +492,6 @@ class Operation : public std::enable_shared_from_this<Operation> {
|
||||
public:
|
||||
virtual ~Operation() = default;
|
||||
|
||||
// Wait for an operation to complete. Throw a
|
||||
// RequiredOperationFailedException if it fails. Mainly for testing.
|
||||
virtual void mustSucceed() = 0;
|
||||
|
||||
virtual db::OperationType getOperationType() const = 0;
|
||||
|
||||
// Did the operation succeed?
|
||||
|
@ -119,7 +119,7 @@ query, and hold the result when it completes. In the above example,
|
||||
we create a connection operation (`connect_op`), run it (which is a
|
||||
non-blocking call), and wait for it to complete (which is a blocking
|
||||
call). Specifically, *no function on any method of any class blocks,
|
||||
except for wait() and mustSucceed()*.
|
||||
except for wait().
|
||||
|
||||
In addition to being able to start a MySQL query or connection "in the
|
||||
background" like the connect above, you can specify a callback, as
|
||||
|
@ -20,12 +20,4 @@ InternalConnection::Status SpecialOperationImpl::runSpecialOperation() {
|
||||
return getOp().runSpecialOperation();
|
||||
}
|
||||
|
||||
void SpecialOperation::mustSucceed() {
|
||||
run();
|
||||
wait();
|
||||
if (!ok()) {
|
||||
throw db::RequiredOperationFailedException(getErrorMsg() + mysql_error());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace facebook::common::mysql_client
|
||||
|
@ -53,8 +53,6 @@ class SpecialOperation : public Operation {
|
||||
impl_->setOperation(*this);
|
||||
}
|
||||
|
||||
void mustSucceed() override;
|
||||
|
||||
virtual InternalConnection::Status runSpecialOperation() = 0;
|
||||
friend SpecialOperationImpl;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user