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

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


#include <dds/error/errors.hpp> #include <dds/error/errors.hpp>
#include <dds/error/toolchain.hpp>
#include <dds/util/http/pool.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>
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) {
[](e_system_error_exc e, neo::url url, http_response_info) {
dds_log(error, dds_log(error,
"An error occured while downloading [.bold.red[{}]]: {}"_styled, "An error occured while downloading [.bold.red[{}]]: {}"_styled,
url.to_string(), url.to_string(),
e.message); e.message);
return 1; 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, dds_log(error,
"Network error communicating with .bold.red[{}://{}:{}]: {}"_styled, "Network error communicating with .bold.red[{}://{}:{}]: {}"_styled,
origin.protocol, origin.protocol,
} }
return 1; 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) { [](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: {}",
} // namespace } // namespace


int dds::handle_cli_errors(std::function<int()> fn) noexcept { 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

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


#include <dds/error/errors.hpp> #include <dds/error/errors.hpp>
#include <dds/error/on_error.hpp>
#include <dds/error/toolchain.hpp>
#include <dds/pkg/db.hpp> #include <dds/pkg/db.hpp>
#include <dds/toolchain/from_json.hpp> #include <dds/toolchain/from_json.hpp>
#include <dds/toolchain/toolchain.hpp> #include <dds/toolchain/toolchain.hpp>
} }
// Convert the given string to a toolchain // Convert the given string to a toolchain
auto& tc_str = *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(":")) { if (tc_str.starts_with(":")) {
DDS_E_SCOPE(e_toolchain_builtin{tc_str});
auto default_tc = tc_str.substr(1); auto default_tc = tc_str.substr(1);
auto tc = dds::toolchain::get_builtin(default_tc); auto tc = dds::toolchain::get_builtin(default_tc);
if (!tc.has_value()) { if (!tc.has_value()) {
} }
return std::move(*tc); return std::move(*tc);
} else { } else {
DDS_E_SCOPE(e_toolchain_file{tc_str});
return parse_toolchain_json5(slurp_file(tc_str)); return parse_toolchain_json5(slurp_file(tc_str));
} }
} }

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

#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