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.
This commit is contained in:
Timothy Flynn 2023-02-09 14:15:58 -05:00 committed by Linus Groh
parent 142f327e63
commit 945f392392
Notes: sideshowbarker 2024-07-17 02:39:10 +09:00

View file

@ -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");