mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +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
Notes:
sideshowbarker
2024-07-17 20:30:06 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/9702f2010fc Pull-request: https://github.com/SerenityOS/serenity/pull/11344 Reviewed-by: https://github.com/alimpfard ✅ Reviewed-by: https://github.com/sin-ack
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
Reference in a new issue