Procházet zdrojové kódy

Better handling of system_error when loading toolchain files

default_compile_flags
vector-of-bool před 3 roky
rodič
revize
2e4ca9b356
3 změnil soubory, kde provedl 51 přidání a 3 odebrání
  1. +22
    -3
      src/dds/cli/error_handler.cpp
  2. +6
    -0
      src/dds/cli/options.cpp
  3. +23
    -0
      src/dds/error/toolchain.hpp

+ 22
- 3
src/dds/cli/error_handler.cpp Zobrazit soubor

@@ -2,6 +2,7 @@
#include "./options.hpp"

#include <dds/error/errors.hpp>
#include <dds/error/toolchain.hpp>
#include <dds/util/http/pool.hpp>
#include <dds/util/log.hpp>
#include <dds/util/result.hpp>
@@ -58,14 +59,14 @@ auto handlers = std::tuple( //
dds_log(critical, "Operation cancelled by the user");
return 2;
},
[](dds::e_system_error_exc e, neo::url url, http_response_info) {
[](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) {
[](e_system_error_exc e, network_origin origin, neo::url* url) {
dds_log(error,
"Network error communicating with .bold.red[{}://{}:{}]: {}"_styled,
origin.protocol,
@@ -77,6 +78,16 @@ auto handlers = std::tuple( //
}
return 1;
},
[](e_system_error_exc err,
e_loading_toolchain,
e_toolchain_file* tc_file,
e_toolchain_builtin*) {
dds_log(error, "Failed to load toolchain: .br.yellow[{}]"_styled, err.message);
if (tc_file) {
dds_log(error, " (While loading from file [.bold.red[{}]])"_styled, tc_file->value);
}
return 1;
},
[](e_system_error_exc exc, boost::leaf::verbose_diagnostic_info const& diag) {
dds_log(critical,
"An unhandled std::system_error arose. THIS IS A DDS BUG! Info: {}",
@@ -91,5 +102,13 @@ auto handlers = std::tuple( //
} // namespace

int dds::handle_cli_errors(std::function<int()> fn) noexcept {
return boost::leaf::try_catch(fn, handlers);
return boost::leaf::try_catch(
[&] {
try {
return fn();
} catch (...) {
capture_exception();
}
},
handlers);
}

+ 6
- 0
src/dds/cli/options.cpp Zobrazit soubor

@@ -1,6 +1,8 @@
#include "./options.hpp"

#include <dds/error/errors.hpp>
#include <dds/error/on_error.hpp>
#include <dds/error/toolchain.hpp>
#include <dds/pkg/db.hpp>
#include <dds/toolchain/from_json.hpp>
#include <dds/toolchain/toolchain.hpp>
@@ -471,7 +473,10 @@ toolchain dds::cli::options::load_toolchain() const {
}
// Convert the given string to a toolchain
auto& tc_str = *toolchain;
DDS_E_SCOPE(e_toolchain_name{tc_str});
DDS_E_SCOPE(e_loading_toolchain{tc_str});
if (tc_str.starts_with(":")) {
DDS_E_SCOPE(e_toolchain_builtin{tc_str});
auto default_tc = tc_str.substr(1);
auto tc = dds::toolchain::get_builtin(default_tc);
if (!tc.has_value()) {
@@ -481,6 +486,7 @@ toolchain dds::cli::options::load_toolchain() const {
}
return std::move(*tc);
} else {
DDS_E_SCOPE(e_toolchain_file{tc_str});
return parse_toolchain_json5(slurp_file(tc_str));
}
}

+ 23
- 0
src/dds/error/toolchain.hpp Zobrazit soubor

@@ -0,0 +1,23 @@
#pragma once

#include <string>

namespace dds {

struct e_loading_toolchain {
std::string value;
};

struct e_toolchain_name {
std::string value;
};

struct e_toolchain_file {
std::string value;
};

struct e_toolchain_builtin {
std::string value;
};

} // namespace dds

Načítá se…
Zrušit
Uložit