diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2016-09-17 19:54:35 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2016-09-17 19:54:35 +0000 |
commit | 6a57bb2e9b5a5e314d9a359da4e6782624fe7591 (patch) | |
tree | 00910e7ab00bd14d04c41ed3a2a7c3062534c4b4 /filedistribution | |
parent | 3cd17b4bd4464df0ffaf28d785e88dfa5736d7c0 (diff) |
No more boost::exception.
Diffstat (limited to 'filedistribution')
17 files changed, 54 insertions, 125 deletions
diff --git a/filedistribution/src/apps/filedistributor/filedistributor.cpp b/filedistribution/src/apps/filedistributor/filedistributor.cpp index 0c89fb08b6b..ae44165057f 100644 --- a/filedistribution/src/apps/filedistributor/filedistributor.cpp +++ b/filedistribution/src/apps/filedistributor/filedistributor.cpp @@ -289,7 +289,7 @@ FileDistributorApplication::Main() { std::string s = boost::diagnostic_information(e); EV_STOPPING(programName, s.c_str()); return 4; - } catch(const FailedListeningException & e) { + } catch(const vespalib::PortListenException & e) { std::string s = boost::diagnostic_information(e); EV_STOPPING(programName, s.c_str()); return 5; @@ -297,27 +297,6 @@ FileDistributorApplication::Main() { std::string s = boost::diagnostic_information(e); EV_STOPPING(programName, s.c_str()); return 99; - } catch(const boost::unknown_exception & e) { - std::string s = boost::diagnostic_information(e); - LOG(warning, "Caught '%s'", s.c_str()); - EV_STOPPING(programName, s.c_str()); - return 255; -#if 0 - /* - These are kept hanging around for reference as to how it was when we just held our ears - singing "na, na, na, na..." no matter if the sun was shining or if the world imploded. - */ - } catch(const boost::exception& e) { - std::string s = boost::diagnostic_information(e); - LOG(error, "Caught '%s'", s.c_str()); - EV_STOPPING(programName, s.c_str()); - return -1; - } catch(const std::string& msg) { - std::string s = "Error: " + msg; - LOG(error, "Caught '%s'", s.c_str()); - EV_STOPPING(programName, s.c_str()); - return -1; -#endif } } diff --git a/filedistribution/src/apps/status/status-filedistribution.cpp b/filedistribution/src/apps/status/status-filedistribution.cpp index d7dc62e29c4..87fa04e503b 100644 --- a/filedistribution/src/apps/status/status-filedistribution.cpp +++ b/filedistribution/src/apps/status/status-filedistribution.cpp @@ -112,7 +112,7 @@ printStatusRetryIfZKProblem(const std::string& zkservers, const std::string& zkL try { return printStatus(zkservers); } catch (ZKNodeDoesNotExistsException& e) { - LOG(debug, "Node does not exists, assuming concurrent update. %s", boost::diagnostic_information(e).c_str()); + LOG(debug, "Node does not exists, assuming concurrent update. %s", e.what()); } catch (ZKSessionExpired& e) { LOG(debug, "Session expired."); diff --git a/filedistribution/src/tests/rpc/CMakeLists.txt b/filedistribution/src/tests/rpc/CMakeLists.txt index faf23f1d464..88ed4527449 100644 --- a/filedistribution/src/tests/rpc/CMakeLists.txt +++ b/filedistribution/src/tests/rpc/CMakeLists.txt @@ -4,6 +4,7 @@ vespa_add_executable(filedistribution_rpc_test_app TEST testfileprovider.cpp DEPENDS filedistribution_filedistributorrpc + filedistribution_common ) target_compile_options(filedistribution_rpc_test_app PRIVATE -DTORRENT_DEBUG -DTORRENT_DISABLE_ENCRYPTION -DTORRENT_DISABLE_DHT -DWITH_SHIPPED_GEOIP_H -DBOOST_ASIO_HASH_MAP_BUCKETS=1021 -DBOOST_EXCEPTION_DISABLE -DBOOST_ASIO_ENABLE_CANCELIO -DBOOST_ASIO_DYN_LINK -DTORRENT_LINKING_SHARED) vespa_add_target_system_dependency(filedistribution_rpc_test_app boost boost_system-mt-d) diff --git a/filedistribution/src/vespa/filedistribution/common/exception.cpp b/filedistribution/src/vespa/filedistribution/common/exception.cpp index 7195a99d702..f886f963837 100644 --- a/filedistribution/src/vespa/filedistribution/common/exception.cpp +++ b/filedistribution/src/vespa/filedistribution/common/exception.cpp @@ -4,10 +4,13 @@ #include <execinfo.h> +namespace filedistribution { + +VESPA_IMPLEMENT_EXCEPTION(FileDoesNotExistException, vespalib::Exception); + std::ostream& -filedistribution::operator<<(std::ostream& stream, const Backtrace& backtrace) { - char** strings = backtrace_symbols( - &*backtrace._frames.begin(), backtrace._size); +operator<<(std::ostream& stream, const Backtrace& backtrace) { + char** strings = backtrace_symbols(&*backtrace._frames.begin(), backtrace._size); stream <<"Backtrace:" <<std::endl; for (size_t i = 0; i<backtrace._size; ++i) { @@ -19,6 +22,8 @@ filedistribution::operator<<(std::ostream& stream, const Backtrace& backtrace) { } -filedistribution::Backtrace::Backtrace() +Backtrace::Backtrace() :_size(backtrace(&*_frames.begin(), _frames.size())) {} + +} diff --git a/filedistribution/src/vespa/filedistribution/common/exception.h b/filedistribution/src/vespa/filedistribution/common/exception.h index ee1f931ade0..deeb054a99a 100644 --- a/filedistribution/src/vespa/filedistribution/common/exception.h +++ b/filedistribution/src/vespa/filedistribution/common/exception.h @@ -1,11 +1,9 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <boost/exception/all.hpp> -#include <boost/current_function.hpp> -#include <boost/exception/all.hpp> #include <boost/array.hpp> #include <boost/version.hpp> +#include <vespa/vespalib/util/exceptions.h> namespace filedistribution { @@ -18,35 +16,13 @@ class Backtrace { Backtrace(); }; +VESPA_DEFINE_EXCEPTION(FileDoesNotExistException, vespalib::Exception); -std::ostream& operator<<(std::ostream& stream, const Backtrace& backtrace); - -namespace errorinfo { -typedef boost::error_info<struct tag_Backtrace, Backtrace> Backtrace; -typedef boost::error_info<struct tag_UserMessage, Backtrace> ExplanationForUser; -typedef boost::error_info<struct tag_TorrentMessage, std::string> TorrentMessage; -} -//Exceptions should inherit virtually from boost and std exception, -//see http://www.boost.org/doc/libs/1_39_0/libs/exception/doc/using_virtual_inheritance_in_exception_types.html -struct Exception : virtual boost::exception, virtual std::exception { - Exception() { - *this << errorinfo::Backtrace(Backtrace()); - } -}; +std::ostream& operator<<(std::ostream& stream, const Backtrace& backtrace); } //namespace filedistribution -#if BOOST_VERSION < 103700 -#define BOOST_THROW_EXCEPTION(x)\ - ::boost::throw_exception( ::boost::enable_error_info(x) << \ - ::boost::throw_function(BOOST_CURRENT_FUNCTION) << \ - ::boost::throw_file(__FILE__) << \ - ::boost::throw_line((int)__LINE__) ) - -#endif - - //********** Begin: Please remove when fixed upstream. //boost 1.36 & 1.37 bugfix: allow attaching a boost::filesytem::path to a boost::exception //using the error info mechanism. diff --git a/filedistribution/src/vespa/filedistribution/distributor/filedownloader.cpp b/filedistribution/src/vespa/filedistribution/distributor/filedownloader.cpp index 72c4f2cbb4a..4ac8bd650ca 100644 --- a/filedistribution/src/vespa/filedistribution/distributor/filedownloader.cpp +++ b/filedistribution/src/vespa/filedistribution/distributor/filedownloader.cpp @@ -125,6 +125,10 @@ createSessionSettings() { } //anonymous namespace +namespace filedistribution { + VESPA_IMPLEMENT_EXCEPTION(NoSuchTorrentException, vespalib::Exception); +} + struct FileDownloader::EventHandler { FileDownloader& _fileDownloader; @@ -138,7 +142,7 @@ struct FileDownloader::EventHandler } void operator()(const libtorrent::listen_failed_alert& alert) const { - throw FailedListeningException(alert.endpoint.address().to_string(), alert.endpoint.port(), alert.message()); + throw vespalib::PortListenException(alert.endpoint.port(), alert.endpoint.address().to_string(), alert.message(), VESPA_STRLOC); } void operator()(const libtorrent::fastresume_rejected_alert& alert) const { LOG(debug, "alert %s: %s", alert.what(), alert.message().c_str()); @@ -251,7 +255,7 @@ FileDownloader::listen() { if (!ec && (_session.listen_port() == _port)) { return; } - throw FailedListeningException(_hostName, _port); + throw vespalib::PortListenException(_port, _hostName, VESPA_STRLOC); } boost::optional< fs::path > diff --git a/filedistribution/src/vespa/filedistribution/distributor/filedownloader.h b/filedistribution/src/vespa/filedistribution/distributor/filedownloader.h index 38de8ac4357..4a40293ae07 100644 --- a/filedistribution/src/vespa/filedistribution/distributor/filedownloader.h +++ b/filedistribution/src/vespa/filedistribution/distributor/filedownloader.h @@ -20,16 +20,7 @@ namespace filedistribution { -struct NoSuchTorrentException : public Exception {}; - -struct FailedListeningException : public Exception { - FailedListeningException(const std::string& hostName, int port, const std::string & message) { - *this << errorinfo::HostName(hostName) << errorinfo::Port(port) << errorinfo::TorrentMessage(message); - } - FailedListeningException(const std::string& hostName, int port) { - *this <<errorinfo::HostName(hostName) << errorinfo::Port(port); - } -}; +VESPA_DEFINE_EXCEPTION(NoSuchTorrentException, vespalib::Exception); class FileDownloader { diff --git a/filedistribution/src/vespa/filedistribution/distributor/filedownloadermanager.cpp b/filedistribution/src/vespa/filedistribution/distributor/filedownloadermanager.cpp index bf17b1bc8d1..ea38f518caa 100644 --- a/filedistribution/src/vespa/filedistribution/distributor/filedownloadermanager.cpp +++ b/filedistribution/src/vespa/filedistribution/distributor/filedownloadermanager.cpp @@ -123,7 +123,7 @@ FileDownloaderManager::SetFinishedDownloadingStatus::operator()( try { _parent._fileDistributionModel->peerFinished(fileReference); - } catch(const FileDistributionModel::NotPeer&) { //Probably a concurrent removal of the torrent. + } catch (const NotPeer &) { //Probably a concurrent removal of the torrent. //improve chance of libtorrent session being updated. std::this_thread::sleep_for(100ms); diff --git a/filedistribution/src/vespa/filedistribution/distributor/hostname.cpp b/filedistribution/src/vespa/filedistribution/distributor/hostname.cpp index acd5c982957..7b33632df81 100644 --- a/filedistribution/src/vespa/filedistribution/distributor/hostname.cpp +++ b/filedistribution/src/vespa/filedistribution/distributor/hostname.cpp @@ -1,22 +1,24 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "hostname.h" -#include <boost/asio.hpp> - +#include <vespa/vespalib/net/socket_address.h> #include <vespa/log/log.h> LOG_SETUP(".hostname"); -#include <vespa/vespalib/net/socket_address.h> -namespace asio = boost::asio; +namespace filedistribution { std::string -filedistribution::lookupIPAddress(const std::string& hostName) +lookupIPAddress(const std::string& hostName) { auto best_addr = vespalib::SocketAddress::select_remote(0, hostName.c_str()); if (!best_addr.valid()) { - BOOST_THROW_EXCEPTION(filedistribution::FailedResolvingHostName(hostName)); + throw filedistribution::FailedResolvingHostName(hostName, VESPA_STRLOC); } const std::string address = best_addr.ip_address(); LOG(debug, "Resolved hostname'%s' as '%s'", hostName.c_str(), address.c_str()); return address; } + +VESPA_IMPLEMENT_EXCEPTION(FailedResolvingHostName, vespalib::Exception); + +} diff --git a/filedistribution/src/vespa/filedistribution/distributor/hostname.h b/filedistribution/src/vespa/filedistribution/distributor/hostname.h index 12732029c92..385a908ab9f 100644 --- a/filedistribution/src/vespa/filedistribution/distributor/hostname.h +++ b/filedistribution/src/vespa/filedistribution/distributor/hostname.h @@ -6,17 +6,8 @@ namespace filedistribution { -namespace errorinfo { -typedef boost::error_info<struct tag_HostName, std::string> HostName; -typedef boost::error_info<struct tag_Port, int> Port; -}; - - std::string lookupIPAddress(const std::string& hostName); -struct FailedResolvingHostName : public Exception { - FailedResolvingHostName(const std::string& hostName) { - *this <<errorinfo::HostName(hostName); - } -}; +VESPA_DEFINE_EXCEPTION(FailedResolvingHostName, vespalib::Exception); + } diff --git a/filedistribution/src/vespa/filedistribution/manager/filedistributionmanager.cpp b/filedistribution/src/vespa/filedistribution/manager/filedistributionmanager.cpp index 057902327a9..c87360f3f67 100644 --- a/filedistribution/src/vespa/filedistribution/manager/filedistributionmanager.cpp +++ b/filedistribution/src/vespa/filedistribution/manager/filedistributionmanager.cpp @@ -58,7 +58,7 @@ std::unique_ptr<ZKLogging> _G_zkLogging; } catch(const ZKException& e) { \ std::stringstream ss; \ ss << "In" << __FUNCTION__ << ": "; \ - ss << diagnosticUserLevelMessage(e); \ + ss << e.what(); \ throwRuntimeException(ss.str().c_str(), env); \ returnStatement; \ } catch(const std::exception& e) { \ diff --git a/filedistribution/src/vespa/filedistribution/model/filedbmodel.h b/filedistribution/src/vespa/filedistribution/model/filedbmodel.h index b575a166701..63894a1f3e5 100644 --- a/filedistribution/src/vespa/filedistribution/model/filedbmodel.h +++ b/filedistribution/src/vespa/filedistribution/model/filedbmodel.h @@ -17,17 +17,11 @@ private: int _fd; }; -struct InvalidProgressException : public Exception { - const char* what() const throw() { - return "Invalid progress information reported by one of the filedistributors"; - } -}; - -struct FileDoesNotExistException : public Exception {}; +VESPA_DEFINE_EXCEPTION(InvalidProgressException, vespalib::Exception); +VESPA_DEFINE_EXCEPTION(InvalidHostStatusException, vespalib::Exception); class FileDBModel { public: - class InvalidHostStatusException : public Exception {}; struct HostStatus { enum State { finished, inProgress, notStarted }; diff --git a/filedistribution/src/vespa/filedistribution/model/filedistributionmodel.h b/filedistribution/src/vespa/filedistribution/model/filedistributionmodel.h index 170c5311bf2..3b4e3784de5 100644 --- a/filedistribution/src/vespa/filedistribution/model/filedistributionmodel.h +++ b/filedistribution/src/vespa/filedistribution/model/filedistributionmodel.h @@ -16,10 +16,10 @@ namespace filedistribution { +VESPA_DEFINE_EXCEPTION(NotPeer, vespalib::Exception); + class FileDistributionModel { public: - class NotPeer : public Exception {}; - typedef boost::signals2::signal<void ()> FilesToDownloadChangedSignal; typedef std::vector<libtorrent::peer_entry> PeerEntries; diff --git a/filedistribution/src/vespa/filedistribution/model/filedistributionmodelimpl.cpp b/filedistribution/src/vespa/filedistribution/model/filedistributionmodelimpl.cpp index 62cd4af940c..01b08e1f377 100644 --- a/filedistribution/src/vespa/filedistribution/model/filedistributionmodelimpl.cpp +++ b/filedistribution/src/vespa/filedistribution/model/filedistributionmodelimpl.cpp @@ -65,6 +65,12 @@ prunePeers(std::vector<std::string> &peers, size_t maxPeers) { } //anonymous namespace +namespace filedistribution { + +VESPA_IMPLEMENT_EXCEPTION(NotPeer, vespalib::Exception); + +} + using filedistribution::FileDistributionModelImpl; struct FileDistributionModelImpl::DeployedFilesChangedCallback : @@ -159,8 +165,8 @@ FileDistributionModelImpl::peerFinished(const std::string& fileReference) { char progress = 100; //percent _zk->setData(path, &progress, sizeof(char), mustExist); - } catch(ZKNodeDoesNotExistsException&) { - BOOST_THROW_EXCEPTION(NotPeer()); + } catch(ZKNodeDoesNotExistsException & e) { + NotPeer(fileReference, e, VESPA_STRLOC); } } diff --git a/filedistribution/src/vespa/filedistribution/model/zkfacade.cpp b/filedistribution/src/vespa/filedistribution/model/zkfacade.cpp index 5d18deed80b..5e09073f8a2 100644 --- a/filedistribution/src/vespa/filedistribution/model/zkfacade.cpp +++ b/filedistribution/src/vespa/filedistribution/model/zkfacade.cpp @@ -579,16 +579,3 @@ ZKLogging::~ZKLogging() _file = nullptr; } } - -const std::string -filedistribution::diagnosticUserLevelMessage(const ZKException& exception) { - const char* indent = " "; - std::ostringstream message; - message <<exception.what(); - - const errorinfo::Path::value_type* path = boost::get_error_info<errorinfo::Path>(exception); - if (path) { - message <<std::endl <<indent <<"Path: " <<*path; - } - return message.str(); -} diff --git a/filedistribution/src/vespa/filedistribution/model/zkfacade.h b/filedistribution/src/vespa/filedistribution/model/zkfacade.h index 7e6db4d381f..08577483908 100644 --- a/filedistribution/src/vespa/filedistribution/model/zkfacade.h +++ b/filedistribution/src/vespa/filedistribution/model/zkfacade.h @@ -16,10 +16,6 @@ typedef _zhandle zhandle_t; namespace filedistribution { -namespace errorinfo { -typedef boost::error_info<struct tag_Path, boost::filesystem::path> Path; -} - class ZKException : public vespalib::Exception { protected: using vespalib::Exception::Exception; @@ -47,11 +43,6 @@ private: const int _zkStatus; }; -const std::string -diagnosticUserLevelMessage(const ZKException& zk); - - - class ZKFacade : public std::enable_shared_from_this<ZKFacade> { volatile bool _retriesEnabled; volatile bool _watchersEnabled; diff --git a/filedistribution/src/vespa/filedistribution/model/zkfiledbmodel.cpp b/filedistribution/src/vespa/filedistribution/model/zkfiledbmodel.cpp index ab886a5889b..d7f0b91360f 100644 --- a/filedistribution/src/vespa/filedistribution/model/zkfiledbmodel.cpp +++ b/filedistribution/src/vespa/filedistribution/model/zkfiledbmodel.cpp @@ -44,6 +44,9 @@ getSortedChildren(ZKFacade& zk, const ZKFileDBModel::Path& path) { } //anonymous namespace +VESPA_IMPLEMENT_EXCEPTION(InvalidProgressException, vespalib::Exception); +VESPA_IMPLEMENT_EXCEPTION(InvalidHostStatusException, vespalib::Exception); + const ZKFileDBModel::Path ZKFileDBModel::_root = "/vespa/filedistribution"; const ZKFileDBModel::Path ZKFileDBModel::_fileDBPath = _root / "files"; const ZKFileDBModel::Path ZKFileDBModel::_hostsPath = _root / "hosts"; @@ -62,8 +65,8 @@ Buffer ZKFileDBModel::getFile(const std::string& fileReference) { try { return _zk->getData(createPath(fileReference)); - } catch(const ZKNodeDoesNotExistsException&) { - throw FileDoesNotExistException(); + } catch(const ZKNodeDoesNotExistsException & e) { + throw FileDoesNotExistException(fileReference, e, VESPA_STRLOC); } } @@ -221,7 +224,7 @@ ZKFileDBModel::getHostStatus(const std::string& hostName) { candidate++; if (candidate != peerEntries.end() && isEntryForHost(hostName, *candidate)) - BOOST_THROW_EXCEPTION(InvalidHostStatusException()); + throw InvalidHostStatusException(path.string(), VESPA_STRLOC); } } @@ -234,8 +237,7 @@ ZKFileDBModel::getHostStatus(const std::string& hostName) { } void -ZKFileDBModel::cleanFiles( - const std::vector<std::string>& filesToPreserve) { +ZKFileDBModel::cleanFiles(const std::vector<std::string>& filesToPreserve) { _zk->retainOnly(_fileDBPath, filesToPreserve); } @@ -257,7 +259,7 @@ ZKFileDBModel::getProgress(const Path& path) { else if (buffer.size() == 0) return 0; else { - throw boost::enable_current_exception(InvalidProgressException()) <<errorinfo::Path(path); + throw InvalidProgressException(path.string(), VESPA_STRLOC); } } catch (ZKNodeDoesNotExistsException& e) { //progress information deleted |