Exceptions

Summary:
Flipper doesn really use library specific exceptions throughout, and that's OK.

Introducing SSLException as a replacement for the existing Folly Async Socket SSL exception.

This exception originally thrown by rsocket. Because we had rsocket and websockets using the same code, websockets were creating and throwing this same exception.

With rsocket gone, we can fully replace the usage of that exception. This is also needed as to decouple Flipper from folly async components.

Reviewed By: fabiomassimo

Differential Revision: D36245624

fbshipit-source-id: f5c97c5efe063280ce95be130008dee7f4e5d788
This commit is contained in:
Lorenzo Blasa
2022-05-12 09:16:13 -07:00
committed by Facebook GitHub Bot
parent 16a0a27672
commit 63dde6e5cf
5 changed files with 40 additions and 20 deletions

View File

@@ -8,13 +8,13 @@
#include "FlipperConnectionManagerImpl.h"
#include <folly/String.h>
#include <folly/futures/Future.h>
#include <folly/io/async/AsyncSocketException.h>
#include <folly/io/async/SSLContext.h>
#include <folly/json.h>
#include <stdexcept>
#include <thread>
#include "ConnectionContextStore.h"
#include "FireAndForgetBasedFlipperResponder.h"
#include "FlipperExceptions.h"
#include "FlipperSocketProvider.h"
#include "FlipperStep.h"
#include "Log.h"
@@ -178,16 +178,11 @@ void FlipperConnectionManagerImpl::startSync() {
}
}
step->complete();
} catch (const folly::AsyncSocketException& e) {
if (e.getType() == folly::AsyncSocketException::SSL_ERROR) {
auto message = std::string(e.what()) +
"\nMake sure the date and time of your device is up to date.";
log(message);
step->fail(message);
} else {
log(e.what());
step->fail(e.what());
}
} catch (const SSLException& e) {
auto message = std::string(e.what()) +
"\nMake sure the date and time of your device is up to date.";
log(message);
step->fail(message);
failedConnectionAttempts_++;
reconnect();
} catch (const std::exception& e) {

View File

@@ -0,0 +1,30 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
namespace facebook {
namespace flipper {
class SSLException : public std::exception {
public:
explicit SSLException(const char* message) : msg_(message) {}
explicit SSLException(const std::string& message) : msg_(message) {}
virtual ~SSLException() noexcept {}
virtual const char* what() const noexcept {
return msg_.c_str();
}
protected:
std::string msg_;
};
} // namespace flipper
} // namespace facebook

View File

@@ -14,7 +14,6 @@
#include <Flipper/Log.h>
#include <folly/String.h>
#include <folly/futures/Future.h>
#include <folly/io/async/AsyncSocketException.h>
#include <folly/io/async/SSLContext.h>
#include <folly/json.h>
#include <websocketpp/common/memory.hpp>

View File

@@ -9,12 +9,12 @@
#include "WebSocketTLSClient.h"
#include <Flipper/ConnectionContextStore.h>
#include <Flipper/FlipperExceptions.h>
#include <Flipper/FlipperTransportTypes.h>
#include <Flipper/FlipperURLSerializer.h>
#include <Flipper/Log.h>
#include <folly/String.h>
#include <folly/futures/Future.h>
#include <folly/io/async/AsyncSocketException.h>
#include <folly/io/async/SSLContext.h>
#include <folly/json.h>
#include <websocketpp/common/memory.hpp>
@@ -246,9 +246,7 @@ void WebSocketTLSClient::onFail(
if (sslError) {
try {
connected_.set_exception(
std::make_exception_ptr(folly::AsyncSocketException(
folly::AsyncSocketException::SSL_ERROR,
"SSL handshake failed")));
std::make_exception_ptr(SSLException("SSL handshake failed")));
} catch (...) {
// set_exception() may throw an exception
// In that case, just set the value to false.