mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:07:35 +00:00
LibAudio: Add Error conversion constructor for LoaderError
This will become necessary shortly when we quickly want to promote an AK::Error to an Audio::LoaderError.
This commit is contained in:
parent
d786142eca
commit
9702f2010f
1 changed files with 14 additions and 0 deletions
|
@ -6,7 +6,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Error.h>
|
||||
#include <AK/FlyString.h>
|
||||
#include <errno.h>
|
||||
|
||||
namespace Audio {
|
||||
|
||||
|
@ -47,6 +49,18 @@ struct LoaderError {
|
|||
|
||||
LoaderError(LoaderError&) = default;
|
||||
LoaderError(LoaderError&&) = default;
|
||||
|
||||
LoaderError(Error&& error)
|
||||
{
|
||||
if (error.is_errno()) {
|
||||
auto code = error.code();
|
||||
description = String::formatted("{} ({})", strerror(code), code);
|
||||
if (code == EBADF || code == EBUSY || code == EEXIST || code == EIO || code == EISDIR || code == ENOENT || code == ENOMEM || code == EPIPE)
|
||||
category = Category::IO;
|
||||
} else {
|
||||
description = error.string_literal();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue