0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 10:08:56 +02:00

ircd::fs::error: Remove fs::error from the ircd::exception hierarchy.

This commit is contained in:
Jason Volk 2019-03-16 17:21:42 -07:00
parent 8450f74450
commit 1ce9ec3f8e
5 changed files with 55 additions and 78 deletions

View file

@ -17,41 +17,37 @@ namespace boost::filesystem
struct filesystem_error;
}
namespace ircd::fs
{
struct error; // does not participate in ircd::exception hierarchy
}
namespace ircd
{
struct error;
std::error_code make_error_code(const boost::filesystem::filesystem_error &);
std::system_error make_system_error(const boost::filesystem::filesystem_error &);
string_view string(const mutable_buffer &, const boost::filesystem::filesystem_error &);
std::string string(const boost::filesystem::filesystem_error &);
}
struct ircd::fs::error
:std::system_error
,ircd::error
{
const char *what() const noexcept override;
static thread_local char buf[1024];
public:
template<class... args>
error(const string_view &fmt = " ",
args&&...);
template<class... args>
error(const std::error_code &,
error(const boost::filesystem::filesystem_error &e,
const string_view &fmt,
args&&...);
template<class... args>
error(const std::system_error &,
error(const std::error_code &e,
const string_view &fmt,
args&&...);
template<class... args>
error(const boost::filesystem::filesystem_error &,
const string_view &fmt,
args&&...);
error(const std::error_code &e);
error(const std::system_error &);
error(const boost::filesystem::filesystem_error &);
error(const boost::filesystem::filesystem_error &e);
};
template<class... args>
@ -64,39 +60,14 @@ ircd::fs::error::error(const boost::filesystem::filesystem_error &e,
}
{}
template<class... args>
ircd::fs::error::error(const std::system_error &e,
const string_view &fmt,
args&&... a)
:error
{
make_error_code(e), fmt, std::forward<args>(a)...
}
{}
template<class... args>
ircd::fs::error::error(const std::error_code &e,
const string_view &fmt,
args&&... a)
:std::system_error
:std::system_error{[&]
() -> std::system_error
{
make_error_code(e)
}
,ircd::error
{
fmt, std::forward<args>(a)...
}
{}
template<class... args>
ircd::fs::error::error(const string_view &fmt,
args&&... a)
:std::system_error
{
make_error_code(std::errc::invalid_argument)
}
,ircd::error
{
fmt, std::forward<args>(a)...
}
fmt::sprintf{buf, fmt, std::forward<args>(a)...};
return {e, buf};
}()}
{}

View file

@ -30,7 +30,6 @@ namespace boost::filesystem {}
namespace ircd::fs
{
struct init;
struct error; // custom exception; still inherits from ircd::error
// Forward interface to boost::filesystem. We do not include boost
// from here; it is used internally only. Some exposed interfaces

View file

@ -1797,6 +1797,35 @@ noexcept
// fs/error.h
//
std::string
ircd::string(const boost::filesystem::filesystem_error &e)
{
return ircd::string(512, [&e]
(const mutable_buffer &buf)
{
return string(buf, e);
});
}
ircd::string_view
ircd::string(const mutable_buffer &buf,
const boost::filesystem::filesystem_error &e)
{
return fmt::sprintf
{
buf, "%s :%s", e.code().category().name(), e.what()
};
}
std::system_error
ircd::make_system_error(const boost::filesystem::filesystem_error &e)
{
return std::system_error
{
make_error_code(e), e.what()
};
}
std::error_code
ircd::make_error_code(const boost::filesystem::filesystem_error &e)
{
@ -1812,38 +1841,15 @@ ircd::make_error_code(const boost::filesystem::filesystem_error &e)
// error::error
//
ircd::fs::error::error(const boost::filesystem::filesystem_error &code)
decltype(ircd::fs::error::buf) thread_local
ircd::fs::error::buf;
ircd::fs::error::error(const boost::filesystem::filesystem_error &e)
:std::system_error
{
make_error_code(code)
make_error_code(e), e.what()
}
{
const string_view &msg
{
// Strip this prefix off the message to simplify it for our user.
lstrip(code.what(), "boost::filesystem::")
};
copy(this->buf, msg);
}
ircd::fs::error::error(const std::system_error &code)
:std::system_error{code}
{
string(this->buf, code);
}
ircd::fs::error::error(const std::error_code &code)
:std::system_error{code}
{
string(this->buf, code);
}
const char *
ircd::fs::error::what()
const noexcept
{
return this->ircd::error::what();
}
///////////////////////////////////////////////////////////////////////////////

View file

@ -1114,6 +1114,7 @@ ircd::mods::paths::add(const string_view &dir)
if(!fs::is_dir(path))
throw fs::error
{
make_error_code(std::errc::not_a_directory),
"path `%s' (%s) is not a directory",
dir,
path

View file

@ -137,7 +137,7 @@ try
::crypto_sign_ed25519_sk_to_pk(pk_data, key.get())
};
}
catch(const fs::error &e)
catch(const std::exception &e)
{
throw error
{