From 9702f2010fc1d0760f8267fa1016cdf131e32532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Fri, 14 Jan 2022 01:14:23 +0100 Subject: [PATCH] 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. --- Userland/Libraries/LibAudio/LoaderError.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Userland/Libraries/LibAudio/LoaderError.h b/Userland/Libraries/LibAudio/LoaderError.h index abf9899b7e..cc630fcdb8 100644 --- a/Userland/Libraries/LibAudio/LoaderError.h +++ b/Userland/Libraries/LibAudio/LoaderError.h @@ -6,7 +6,9 @@ #pragma once +#include #include +#include 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(); + } + } }; }