GPUDevice: Use Error class for initialization errors
This commit is contained in:
@ -28,21 +28,26 @@ void Error::Clear()
|
||||
}
|
||||
|
||||
void Error::SetErrno(int err)
|
||||
{
|
||||
SetErrno(std::string_view(), err);
|
||||
}
|
||||
|
||||
void Error::SetErrno(std::string_view prefix, int err)
|
||||
{
|
||||
m_type = Type::Errno;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
char buf[128];
|
||||
if (strerror_s(buf, sizeof(buf), err) == 0)
|
||||
m_description = fmt::format("errno {}: {}", err, buf);
|
||||
m_description = fmt::format("{}errno {}: {}", prefix, err, buf);
|
||||
else
|
||||
m_description = fmt::format("errno {}: <Could not get error message>", err);
|
||||
m_description = fmt::format("{}errno {}: <Could not get error message>", prefix, err);
|
||||
#else
|
||||
const char* buf = std::strerror(err);
|
||||
if (buf)
|
||||
m_description = fmt::format("errno {}: {}", err, buf);
|
||||
m_description = fmt::format("{}errno {}: {}", prefix, err, buf);
|
||||
else
|
||||
m_description = fmt::format("errno {}: <Could not get error message>", err);
|
||||
m_description = fmt::format("{}errno {}: <Could not get error message>", prefix, err);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -52,20 +57,44 @@ void Error::SetErrno(Error* errptr, int err)
|
||||
errptr->SetErrno(err);
|
||||
}
|
||||
|
||||
void Error::SetErrno(Error* errptr, std::string_view prefix, int err)
|
||||
{
|
||||
if (errptr)
|
||||
errptr->SetErrno(prefix, err);
|
||||
}
|
||||
|
||||
void Error::SetString(std::string description)
|
||||
{
|
||||
m_type = Type::User;
|
||||
m_description = std::move(description);
|
||||
}
|
||||
|
||||
void Error::SetStringView(std::string_view description)
|
||||
{
|
||||
m_type = Type::User;
|
||||
m_description = std::string(description);
|
||||
}
|
||||
|
||||
void Error::SetString(Error* errptr, std::string description)
|
||||
{
|
||||
if (errptr)
|
||||
errptr->SetString(std::move(description));
|
||||
}
|
||||
|
||||
void Error::SetStringView(Error* errptr, std::string_view description)
|
||||
{
|
||||
if (errptr)
|
||||
errptr->SetStringView(std::move(description));
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
void Error::SetWin32(unsigned long err)
|
||||
{
|
||||
SetWin32(std::string_view(), err);
|
||||
}
|
||||
|
||||
void Error::SetWin32(std::string_view prefix, unsigned long err)
|
||||
{
|
||||
m_type = Type::Win32;
|
||||
|
||||
@ -75,11 +104,11 @@ void Error::SetWin32(unsigned long err)
|
||||
if (r > 0)
|
||||
{
|
||||
m_description =
|
||||
fmt::format("Win32 Error {}: {}", err, StringUtil::WideStringToUTF8String(std::wstring_view(buf, r)));
|
||||
fmt::format("{}Win32 Error {}: {}", prefix, err, StringUtil::WideStringToUTF8String(std::wstring_view(buf, r)));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_description = fmt::format("Win32 Error {}: <Could not resolve system error ID>", err);
|
||||
m_description = fmt::format("{}Win32 Error {}: <Could not resolve system error ID>", prefix, err);
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,7 +118,18 @@ void Error::SetWin32(Error* errptr, unsigned long err)
|
||||
errptr->SetWin32(err);
|
||||
}
|
||||
|
||||
void Error::SetWin32(Error* errptr, std::string_view prefix, unsigned long err)
|
||||
{
|
||||
if (errptr)
|
||||
errptr->SetWin32(prefix, err);
|
||||
}
|
||||
|
||||
void Error::SetHResult(long err)
|
||||
{
|
||||
SetHResult(std::string_view(), err);
|
||||
}
|
||||
|
||||
void Error::SetHResult(std::string_view prefix, long err)
|
||||
{
|
||||
m_type = Type::HResult;
|
||||
|
||||
@ -99,11 +139,11 @@ void Error::SetHResult(long err)
|
||||
if (r > 0)
|
||||
{
|
||||
m_description =
|
||||
fmt::format("HRESULT {:08X}: {}", err, StringUtil::WideStringToUTF8String(std::wstring_view(buf, r)));
|
||||
fmt::format("{}HRESULT {:08X}: {}", prefix, err, StringUtil::WideStringToUTF8String(std::wstring_view(buf, r)));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_description = fmt::format("HRESULT {:08X}: <Could not resolve system error ID>", err);
|
||||
m_description = fmt::format("{}HRESULT {:08X}: <Could not resolve system error ID>", prefix, err);
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,15 +153,26 @@ void Error::SetHResult(Error* errptr, long err)
|
||||
errptr->SetHResult(err);
|
||||
}
|
||||
|
||||
void Error::SetHResult(Error* errptr, std::string_view prefix, long err)
|
||||
{
|
||||
if (errptr)
|
||||
errptr->SetHResult(prefix, err);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void Error::SetSocket(int err)
|
||||
{
|
||||
SetSocket(std::string_view(), err);
|
||||
}
|
||||
|
||||
void Error::SetSocket(std::string_view prefix, int err)
|
||||
{
|
||||
// Socket errors are win32 errors on windows
|
||||
#ifdef _WIN32
|
||||
SetWin32(err);
|
||||
SetWin32(prefix, err);
|
||||
#else
|
||||
SetErrno(err);
|
||||
SetErrno(prefix, err);
|
||||
#endif
|
||||
m_type = Type::Socket;
|
||||
}
|
||||
@ -132,6 +183,12 @@ void Error::SetSocket(Error* errptr, int err)
|
||||
errptr->SetSocket(err);
|
||||
}
|
||||
|
||||
void Error::SetSocket(Error* errptr, std::string_view prefix, int err)
|
||||
{
|
||||
if (errptr)
|
||||
errptr->SetSocket(prefix, err);
|
||||
}
|
||||
|
||||
Error Error::CreateNone()
|
||||
{
|
||||
return Error();
|
||||
|
||||
Reference in New Issue
Block a user