Browse Source

More error handling to help diagnose issues in CI

default_compile_flags
vector-of-bool 3 years ago
parent
commit
5fb021bebf
3 changed files with 25 additions and 10 deletions
  1. +0
    -7
      src/dds/cli/cmd/repoman_add.cpp
  2. +22
    -0
      src/dds/cli/error_handler.cpp
  3. +3
    -3
      src/dds/util/http/pool.cpp

+ 0
- 7
src/dds/cli/cmd/repoman_add.cpp View File

[](dds::e_system_error_exc e, dds::e_open_repo_db db) { [](dds::e_system_error_exc e, dds::e_open_repo_db db) {
dds_log(error, "Error while opening repository database {}: {}", db.path, e.message); dds_log(error, "Error while opening repository database {}: {}", db.path, e.message);
return 1; return 1;
},
[](dds::e_system_error_exc e, neo::url url, http_response_info) {
dds_log(error,
"An error occured while downloading [.bold.red[{}]]: {}"_styled,
url.to_string(),
e.message);
return 1;
}); });
} }



+ 22
- 0
src/dds/cli/error_handler.cpp View File

#include "./options.hpp" #include "./options.hpp"


#include <dds/error/errors.hpp> #include <dds/error/errors.hpp>
#include <dds/util/http/pool.hpp>
#include <dds/util/log.hpp> #include <dds/util/log.hpp>
#include <dds/util/result.hpp> #include <dds/util/result.hpp>
#include <dds/util/signal.hpp> #include <dds/util/signal.hpp>
#include <boost/leaf/handle_error.hpp> #include <boost/leaf/handle_error.hpp>
#include <boost/leaf/handle_exception.hpp> #include <boost/leaf/handle_exception.hpp>
#include <boost/leaf/result.hpp> #include <boost/leaf/result.hpp>
#include <fansi/styled.hpp>
#include <fmt/ostream.h> #include <fmt/ostream.h>
#include <json5/parse_data.hpp> #include <json5/parse_data.hpp>
#include <neo/scope.hpp> #include <neo/scope.hpp>
#include <fstream> #include <fstream>


using namespace dds; using namespace dds;
using namespace fansi::literals;


namespace { namespace {


dds_log(critical, "Operation cancelled by the user"); dds_log(critical, "Operation cancelled by the user");
return 2; return 2;
}, },
[](dds::e_system_error_exc e, neo::url url, http_response_info) {
dds_log(error,
"An error occured while downloading [.bold.red[{}]]: {}"_styled,
url.to_string(),
e.message);
return 1;
},
[](dds::e_system_error_exc e, network_origin origin, neo::url* url) {
dds_log(error,
"Network error communicating with .bold.red[{}://{}:{}]: {}"_styled,
origin.protocol,
origin.hostname,
origin.port,
e.message);
if (url) {
dds_log(error, " (While accessing URL [.bold.red[{}]])"_styled, url->to_string());
}
return 1;
},
[](e_system_error_exc exc, boost::leaf::verbose_diagnostic_info const& diag) { [](e_system_error_exc exc, boost::leaf::verbose_diagnostic_info const& diag) {
dds_log(critical, dds_log(critical,
"An unhandled std::system_error arose. THIS IS A DDS BUG! Info: {}", "An unhandled std::system_error arose. THIS IS A DDS BUG! Info: {}",

+ 3
- 3
src/dds/util/http/pool.cpp View File



if (resp.is_error()) { if (resp.is_error()) {
client.discard_body(resp); client.discard_body(resp);
throw boost::leaf::exception(http_status_error("Received an error from HTTP"));
throw BOOST_LEAF_EXCEPTION(http_status_error("Received an error from HTTP"));
} }


if (resp.is_redirect()) { if (resp.is_redirect()) {
client.discard_body(resp); client.discard_body(resp);
if (i == 100) { if (i == 100) {
throw boost::leaf::exception(
throw BOOST_LEAF_EXCEPTION(
http_server_error("Encountered over 100 HTTP redirects. Request aborted.")); http_server_error("Encountered over 100 HTTP redirects. Request aborted."));
} }
auto loc = resp.headers.find("Location"); auto loc = resp.headers.find("Location");
if (!loc) { if (!loc) {
throw boost::leaf::exception(
throw BOOST_LEAF_EXCEPTION(
http_server_error("Server sent an invalid response of a 30x redirect without a " http_server_error("Server sent an invalid response of a 30x redirect without a "
"'Location' header")); "'Location' header"));
} }

Loading…
Cancel
Save