mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-13 14:27:30 -04:00
refactor: provide exception_str wrapper
This commit is contained in:
parent
f8efbdc4a8
commit
9c8fd29ec2
@ -23,6 +23,7 @@
|
||||
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <exception>
|
||||
#include <filesystem>
|
||||
#include <iosfwd>
|
||||
#include <span>
|
||||
@ -78,4 +79,7 @@ std::string_view basename(std::string_view path);
|
||||
|
||||
void ensure_binary_mode(std::ostream& os);
|
||||
|
||||
std::string exception_str(std::exception const& e);
|
||||
std::string exception_str(std::exception_ptr const& e);
|
||||
|
||||
} // namespace dwarfs
|
||||
|
@ -26,8 +26,6 @@
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <folly/String.h>
|
||||
|
||||
#ifdef DWARFS_USE_EXCEPTION_TRACER
|
||||
#include <folly/experimental/exception_tracer/ExceptionTracer.h>
|
||||
#endif
|
||||
@ -86,8 +84,8 @@ void dump_exceptions() {
|
||||
|
||||
void handle_nothrow(char const* expr, char const* file, int line) {
|
||||
std::cerr << "Expression `" << expr << "` threw `"
|
||||
<< folly::exceptionStr(std::current_exception()) << "` in " << file
|
||||
<< "(" << line << ")\n";
|
||||
<< exception_str(std::current_exception()) << "` in " << file << "("
|
||||
<< line << ")\n";
|
||||
do_terminate();
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include <dwarfs/options.h>
|
||||
#include <dwarfs/os_access.h>
|
||||
#include <dwarfs/progress.h>
|
||||
#include <dwarfs/util.h>
|
||||
|
||||
template <typename T, typename U>
|
||||
class fmt::formatter<std::pair<T, U>> {
|
||||
@ -289,7 +290,7 @@ void file_scanner_<LoggerPolicy>::scan_dedupe(file* p) {
|
||||
cs.finalize(&start_hash);
|
||||
} catch (...) {
|
||||
LOG_ERROR << "failed to map file " << p->path_as_string() << ": "
|
||||
<< folly::exceptionStr(std::current_exception())
|
||||
<< exception_str(std::current_exception())
|
||||
<< ", creating empty file";
|
||||
++prog_.errors;
|
||||
p->set_invalid();
|
||||
@ -422,7 +423,7 @@ void file_scanner_<LoggerPolicy>::hash_file(file* p) {
|
||||
mm = os_.map_file(p->fs_path(), size);
|
||||
} catch (...) {
|
||||
LOG_ERROR << "failed to map file " << p->path_as_string() << ": "
|
||||
<< folly::exceptionStr(std::current_exception())
|
||||
<< exception_str(std::current_exception())
|
||||
<< ", creating empty file";
|
||||
++prog_.errors;
|
||||
p->set_invalid();
|
||||
|
@ -300,14 +300,14 @@ bool filesystem_extractor_<LoggerPolicy>::extract(
|
||||
}
|
||||
sem.post(bs);
|
||||
} catch (archive_error const& e) {
|
||||
LOG_ERROR << folly::exceptionStr(e);
|
||||
LOG_ERROR << exception_str(e);
|
||||
++hard_error;
|
||||
} catch (...) {
|
||||
if (opts.continue_on_error) {
|
||||
LOG_WARN << folly::exceptionStr(std::current_exception());
|
||||
LOG_WARN << exception_str(std::current_exception());
|
||||
++soft_error;
|
||||
} else {
|
||||
LOG_ERROR << folly::exceptionStr(std::current_exception());
|
||||
LOG_ERROR << exception_str(std::current_exception());
|
||||
++hard_error;
|
||||
}
|
||||
archive_entry_free(ae);
|
||||
@ -328,7 +328,7 @@ bool filesystem_extractor_<LoggerPolicy>::extract(
|
||||
try {
|
||||
check_result(::archive_write_header(a_, ae));
|
||||
} catch (...) {
|
||||
LOG_ERROR << folly::exceptionStr(std::current_exception());
|
||||
LOG_ERROR << exception_str(std::current_exception());
|
||||
hard_error = true;
|
||||
}
|
||||
});
|
||||
|
@ -885,7 +885,7 @@ int filesystem_<LoggerPolicy>::check(filesystem_check_level level,
|
||||
}
|
||||
}
|
||||
} catch (std::exception const& e) {
|
||||
LOG_ERROR << folly::exceptionStr(e);
|
||||
LOG_ERROR << exception_str(e);
|
||||
++errors;
|
||||
}
|
||||
}
|
||||
@ -894,7 +894,7 @@ int filesystem_<LoggerPolicy>::check(filesystem_check_level level,
|
||||
try {
|
||||
meta_.check_consistency();
|
||||
} catch (std::exception const& e) {
|
||||
LOG_ERROR << folly::exceptionStr(e);
|
||||
LOG_ERROR << exception_str(e);
|
||||
++errors;
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,6 @@
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <folly/Demangle.h>
|
||||
#include <folly/String.h>
|
||||
#include <folly/sorted_vector_types.h>
|
||||
|
||||
#include <dwarfs/categorizer.h>
|
||||
@ -60,6 +59,7 @@
|
||||
#include <dwarfs/script.h>
|
||||
#include <dwarfs/similarity.h>
|
||||
#include <dwarfs/similarity_ordering.h>
|
||||
#include <dwarfs/util.h>
|
||||
|
||||
#include <dwarfs/gen-cpp2/metadata_types.h>
|
||||
|
||||
@ -737,8 +737,7 @@ void inode_manager_<LoggerPolicy>::try_scan_invalid(internal::worker_group& wg,
|
||||
|
||||
for (auto const& [fp, ep] : errors) {
|
||||
LOG_ERROR << "failed to map file \"" << fp->path_as_string()
|
||||
<< "\": " << folly::exceptionStr(ep)
|
||||
<< ", creating empty inode";
|
||||
<< "\": " << exception_str(ep) << ", creating empty inode";
|
||||
++prog_.errors;
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <folly/String.h>
|
||||
#include <folly/container/Enumerate.h>
|
||||
#include <folly/container/EvictingCacheMap.h>
|
||||
#include <folly/stats/Histogram.h>
|
||||
@ -41,6 +40,7 @@
|
||||
#include <dwarfs/logger.h>
|
||||
#include <dwarfs/options.h>
|
||||
#include <dwarfs/performance_monitor.h>
|
||||
#include <dwarfs/util.h>
|
||||
|
||||
namespace dwarfs::internal {
|
||||
|
||||
@ -345,7 +345,7 @@ inode_reader_<LoggerPolicy>::read_internal(uint32_t inode, size_t size,
|
||||
}
|
||||
return num_read;
|
||||
} catch (...) {
|
||||
LOG_ERROR << folly::exceptionStr(std::current_exception());
|
||||
LOG_ERROR << exception_str(std::current_exception());
|
||||
}
|
||||
|
||||
return -EIO;
|
||||
|
@ -301,7 +301,7 @@ class basic_worker_group final : public worker_group::impl, private Policy {
|
||||
std::visit([](auto&& j) { j(); }, job);
|
||||
} catch (...) {
|
||||
LOG_FATAL << "exception thrown in worker thread: "
|
||||
<< folly::exceptionStr(std::current_exception());
|
||||
<< exception_str(std::current_exception());
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if (is_background) {
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#include <folly/String.h>
|
||||
#include <folly/experimental/symbolizer/SignalHandler.h>
|
||||
|
||||
#include <dwarfs/error.h>
|
||||
@ -43,8 +42,7 @@ int safe_main(std::function<int(void)> fn) {
|
||||
|
||||
return fn();
|
||||
} catch (...) {
|
||||
std::cerr << "ERROR: " << folly::exceptionStr(std::current_exception())
|
||||
<< "\n";
|
||||
std::cerr << "ERROR: " << exception_str(std::current_exception()) << "\n";
|
||||
dump_exceptions();
|
||||
}
|
||||
return 1;
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <folly/ExceptionString.h>
|
||||
#include <folly/system/HardwareConcurrency.h>
|
||||
|
||||
#include <fmt/format.h>
|
||||
@ -437,7 +436,7 @@ scanner_<LoggerPolicy>::add_entry(std::filesystem::path const& name,
|
||||
|
||||
return pe;
|
||||
} catch (const std::system_error& e) {
|
||||
LOG_ERROR << "error reading entry: " << folly::exceptionStr(e);
|
||||
LOG_ERROR << "error reading entry: " << exception_str(e);
|
||||
prog.errors++;
|
||||
}
|
||||
|
||||
@ -514,7 +513,7 @@ scanner_<LoggerPolicy>::scan_tree(std::filesystem::path const& path,
|
||||
prog.dirs_scanned++;
|
||||
} catch (const std::system_error& e) {
|
||||
LOG_ERROR << "cannot read directory `" << ppath
|
||||
<< "`: " << folly::exceptionStr(e);
|
||||
<< "`: " << exception_str(e);
|
||||
prog.errors++;
|
||||
}
|
||||
}
|
||||
@ -801,7 +800,7 @@ void scanner_<LoggerPolicy>::scan(
|
||||
} else {
|
||||
for (auto& [fp, e] : errors) {
|
||||
LOG_ERROR << "failed to map file " << fp->path_as_string()
|
||||
<< ": " << folly::exceptionStr(e)
|
||||
<< ": " << exception_str(e)
|
||||
<< ", creating empty inode";
|
||||
++prog.errors;
|
||||
}
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include <date/date.h>
|
||||
|
||||
#include <folly/Conv.h>
|
||||
#include <folly/ExceptionString.h>
|
||||
#include <folly/String.h>
|
||||
#include <folly/portability/Fcntl.h>
|
||||
#include <folly/portability/Windows.h>
|
||||
@ -192,7 +193,7 @@ file_off_t parse_image_offset(std::string const& str) {
|
||||
auto ce = folly::makeConversionError(off.error(), str);
|
||||
DWARFS_THROW(runtime_error,
|
||||
fmt::format("failed to parse image offset: {} ({})", str,
|
||||
folly::exceptionStr(ce)));
|
||||
exception_str(ce)));
|
||||
}
|
||||
|
||||
if (off.value() < 0) {
|
||||
@ -377,4 +378,12 @@ void ensure_binary_mode(std::ostream& os [[maybe_unused]]) {
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string exception_str(std::exception const& e) {
|
||||
return folly::exceptionStr(e).toStdString();
|
||||
}
|
||||
|
||||
std::string exception_str(std::exception_ptr const& e) {
|
||||
return folly::exceptionStr(e).toStdString();
|
||||
}
|
||||
|
||||
} // namespace dwarfs
|
||||
|
@ -263,10 +263,10 @@ auto checked_call(LogProxy& log_, T&& f) -> decltype(std::forward<T>(f)()) {
|
||||
try {
|
||||
return std::forward<T>(f)();
|
||||
} catch (dwarfs::system_error const& e) {
|
||||
LOG_ERROR << folly::exceptionStr(e);
|
||||
LOG_ERROR << exception_str(e);
|
||||
return e.get_errno();
|
||||
} catch (std::exception const& e) {
|
||||
LOG_ERROR << folly::exceptionStr(e);
|
||||
LOG_ERROR << exception_str(e);
|
||||
return EIO;
|
||||
}
|
||||
}
|
||||
@ -1580,10 +1580,10 @@ int dwarfs_main(int argc, sys_char** argv, iolayer const& iol) {
|
||||
}
|
||||
}
|
||||
} catch (std::filesystem::filesystem_error const& e) {
|
||||
iol.err << folly::exceptionStr(e) << "\n";
|
||||
iol.err << exception_str(e) << "\n";
|
||||
return 1;
|
||||
} catch (std::exception const& e) {
|
||||
iol.err << "error: " << folly::exceptionStr(e) << "\n";
|
||||
iol.err << "error: " << exception_str(e) << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1620,7 +1620,7 @@ int dwarfs_main(int argc, sys_char** argv, iolayer const& iol) {
|
||||
load_filesystem<prod_logger_policy>(userdata);
|
||||
}
|
||||
} catch (std::exception const& e) {
|
||||
LOG_ERROR << "error initializing file system: " << folly::exceptionStr(e);
|
||||
LOG_ERROR << "error initializing file system: " << exception_str(e);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,6 @@
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include <folly/String.h>
|
||||
|
||||
#include <dwarfs/conv.h>
|
||||
#include <dwarfs/file_stat.h>
|
||||
#include <dwarfs/filesystem_v2.h>
|
||||
@ -118,10 +116,10 @@ int dwarfsbench_main(int argc, sys_char** argv, iolayer const& iol) {
|
||||
fs.read(fh, buf.data(), buf.size());
|
||||
}
|
||||
} catch (std::exception const& e) {
|
||||
iol.err << "error: " << folly::exceptionStr(e) << "\n";
|
||||
iol.err << "error: " << exception_str(e) << "\n";
|
||||
} catch (...) {
|
||||
iol.err << "error: "
|
||||
<< folly::exceptionStr(std::current_exception()) << "\n";
|
||||
iol.err << "error: " << exception_str(std::current_exception())
|
||||
<< "\n";
|
||||
dump_exceptions();
|
||||
}
|
||||
});
|
||||
@ -130,7 +128,7 @@ int dwarfsbench_main(int argc, sys_char** argv, iolayer const& iol) {
|
||||
|
||||
pool.wait();
|
||||
} catch (std::exception const& e) {
|
||||
iol.err << "error: " << folly::exceptionStr(e) << "\n";
|
||||
iol.err << "error: " << exception_str(e) << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include <fmt/ranges.h>
|
||||
#endif
|
||||
|
||||
#include <folly/String.h>
|
||||
#include <folly/portability/Unistd.h>
|
||||
#include <folly/system/HardwareConcurrency.h>
|
||||
|
||||
@ -350,7 +349,7 @@ int dwarfsck_main(int argc, sys_char** argv, iolayer const& iol) {
|
||||
}
|
||||
}
|
||||
} catch (std::exception const& e) {
|
||||
iol.err << folly::exceptionStr(e) << "\n";
|
||||
iol.err << exception_str(e) << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,7 @@ int dwarfsextract_main(int argc, sys_char** argv, iolayer const& iol) {
|
||||
perfmon->summarize(iol.err);
|
||||
}
|
||||
} catch (std::exception const& e) {
|
||||
iol.err << folly::exceptionStr(e) << "\n";
|
||||
iol.err << exception_str(e) << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1356,7 +1356,7 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer const& iol) {
|
||||
options.inode.categorizer_mgr.reset();
|
||||
}
|
||||
} catch (std::exception const& e) {
|
||||
LOG_ERROR << folly::exceptionStr(e);
|
||||
LOG_ERROR << exception_str(e);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user