From 945f392392138bafcaa47a0486b627db7f4c4e97 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 9 Feb 2023 14:15:58 -0500 Subject: [PATCH] AK: Add an explicit Error factory to copy an existing error As of now, there is a default copy constructor on Error. A future commit will make this non-public to prevent implicit copies, so to prepare for that, this adds a factory for the few cases where a copy is really needed. --- AK/Error.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/AK/Error.h b/AK/Error.h index 0993f337df1..4a04c69c805 100644 --- a/AK/Error.h +++ b/AK/Error.h @@ -25,6 +25,11 @@ public: [[nodiscard]] static Error from_syscall(StringView syscall_name, int rc) { return Error(syscall_name, rc); } [[nodiscard]] static Error from_string_view(StringView string_literal) { return Error(string_literal); } + [[nodiscard]] static Error copy(Error const& error) + { + return Error(error); + } + // NOTE: Prefer `from_string_literal` when directly typing out an error message: // // return Error::from_string_literal("Class: Some failure");