summaryrefslogtreecommitdiff
path: root/AK/Error.h
AgeCommit message (Collapse)Author
2023-02-10AK: Provide `is_errno` for Kernel ErrorsTim Schumacher
It wouldn't make much sense on its own (as the Kernel only has errno Errors), but it's an easy fix for not having to ifdef away every single usage of `is_errno` in code that is shared between Userland and Kernel.
2023-02-10AK: Allow explicitly copying Errors in the KernelTim Schumacher
2023-02-10AK: Fix a linting issue in `Error.h`Tim Schumacher
I'm not sure why, but `clang-format` gets unhappy if we touch the adjacent line.
2023-02-10AK: Disallow returning of string literals for errors in kernel codeLiav A
This code should not be used in the kernel - we should always propagate proper errno codes in case we need to return those to userland so it could decode it in a reasonable way.
2023-02-10AK: Add a new method to propagate errno while printing errors in KernelLiav A
This new method is meant to be used in both userspace and kernel code. The idea is to allow printing of a verbose message and then returning an errno code which is the proper mechanism for kernel code because we should almost always assume that such error will be propagated back to userspace in some way, so the userspace code could reasonably decode it. For userspace code however, this new method is meant to be a simple wrapper for Error::from_string_view, because for most invocations, it's much more useful to have a verbose & literal error than a errno code, so we simply ignore that errno code completely in such context.
2023-02-10AK: Disallow implicitly copying Error and ErrorOr instancesTimothy Flynn
In the rare cases that a copy is actually needed, the Error::copy factory will suffice.
2023-02-10AK: Add an explicit Error factory to copy an existing errorTimothy Flynn
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.
2023-01-07Everywhere: Remove "LibC/" includes, add lint-rule against itBen Wiederhake
2022-12-28AK: Fix constructing ErrorOr from ErrorOr of a related typeSam Atkins
Mark other ErrorOr types as friends, and fix a typo in the && constructor, so that we can create an ErrorOr<Core::Object> from an ErrorOr<GUI::Widget>. Also, add some requires() clauses to these constructors so the error messages are clearer.
2022-12-26AK: Mark Error::from_ functions as [[nodiscard]]Nico Weber
Prevents mistakes like the one fixed in #16672.
2022-12-22AK: Rearrange Error's members to reduce its size by 8 bytesTimothy Flynn
This shrinks sizeof(Error) from 32 bytes to 24 bytes, which in turn will shrink sizeof(ErrorOr<T>) by the same amount (in cases where sizeof(T) is less than sizeof(Error)).
2022-12-11AK: Add a Error::__jakt_from_string_literal(StringView) factory functionAli Mohammad Pur
Note that Jakt only allows StringView creation from string literals, so none of the invariants in the class are broken by this (if used only from within Jakt).
2022-12-11AK: Let ErrorOr<T, E> expose its result/error typesAli Mohammad Pur
`ErrorOr<T, E>::ResultType` can now refer to `T`.
2022-12-11AK: Elaborate the Error constructors a bitAli Mohammad Pur
The old constraints were making clang mad, so express them in a less complex way.
2022-12-03Everywhere: Run clang-formatLinus Groh
2022-11-26AK: Make it possible to not `using` AK classes into the global namespaceAndreas Kling
This patch adds the `USING_AK_GLOBALLY` macro which is enabled by default, but can be overridden by build flags. This is a step towards integrating Jakt and AK types.
2022-10-10Everywhere: Replace uses of __serenity__ with AK_OS_SERENITYAndrew Kaster
Now that we have OS macros for essentially every supported OS, let's try to use them everywhere.
2022-10-07AK: Change ErrorOr to contain a Variant rather than inherit from itTimothy Flynn
GCC seems to get tripped up over this inheritance when converting from an ErrorOr<StringView> to the partially specialized ErrorOr<void>. See the following snippet: NEVER_INLINE ErrorOr<StringView> foo() { auto string = "abc"sv; outln("{:p}", string.characters_without_null_termination()); return string; } NEVER_INLINE ErrorOr<void> bar() { auto string = TRY(foo()); outln("{:p}", string.characters_without_null_termination()); VERIFY(!string.starts_with('#')); return {}; } int main() { MUST(bar()); } On some machines, bar() will contain a StringView whose pointer has had its upper bits set to 0: 0x000000010cafd6f8 0x000000000cafd6f8 I'm not 100% clear on what's happening in the default-generated Variant destructor that causes this. Probably worth investigating further. The error would also be alleviated by making the Variant destructor virtual, but rather than that, let's make ErrorOr simply contain a Variant rather than inherit from it. Fixes #15449.
2022-09-27AK: Make ErrorOr::error() const and return a const referenceLucas CHOLLET
2022-07-12Everywhere: Split Error::from_string_literal and Error::from_string_viewsin-ack
Error::from_string_literal now takes direct char const*s, while Error::from_string_view does what Error::from_string_literal used to do: taking StringViews. This change will remove the need to insert `sv` after error strings when returning string literal errors once StringView(char const*) is removed. No functional changes.
2022-06-09AK: Add Error::operator==(Error const&)Lucas CHOLLET
2022-02-16AK: VERIFY inside release_value_but_fixme_should_propagate_errors()Sam Atkins
While the code did already VERIFY that the ErrorOr holds a value, this was done by Variant, so the error message was just that `has<T>()` is false. This is less helpful than I would like, especially if backtraces are not working and this is all you have to go on. Adding this extra VERIFY means the assertion message (`!is_error()`) is easier to understand.
2021-12-20AK+LibMain: Improve formatter for AK::Error in userspaceAndreas Kling
Print the full associated string metadata by default (if available.)
2021-12-16Kernel+LibC: Move errno definitions to Kernel/API/POSIXsin-ack
This fixes at least half of our LibC includes in the kernel. The source of truth for errno codes and their description strings now lives in Kernel/API/POSIX/errno.h as an enumeration, which LibC includes.
2021-12-16AK+Tests: Use less space in ErrorOrBen Wiederhake
2021-12-05AK: Implement missing const getters in AK::Error, fix typoBen Wiederhake
Note that the return type for the non-const method error() changed. This is most likely an accident, hidden by the fact that ErrorType typically is Error.
2021-11-22AK+LibSystem+LibMain: Add Error::from_syscall() for syscall failuresAndreas Kling
This creates an error that contains the name of the syscall that failed. This allows error handlers to print out the name of the call if they want to. :^)
2021-11-17AK: Convert AK::Format formatting helpers to returning ErrorOr<void>Andreas Kling
This isn't a complete conversion to ErrorOr<void>, but a good chunk. The end goal here is to propagate buffer allocation failures to the caller, and allow the use of TRY() with formatting functions.
2021-11-17AK: Forward declare Error and ErrorOr in AK/Forward.hAndreas Kling
2021-11-08AK: Add some more ways to construct Error and ErrorOr<T>Andreas Kling
This is preparation for using Error in the kernel instead of KResult.
2021-11-08AK: Make Error.h pull in Try.hAndreas Kling
Users of this API will want TRY().
2021-11-08AK: Allow subclassing ErrorAndreas Kling
2021-11-08AK: Make Error and ErrorOr<T> work in Lagom as well :^)Andreas Kling
ErrnoCode is not a thing outside __serenity__, so let's not make assumptions about it existing.
2021-11-08AK: Add ErrorOr<T>::release_value_but_fixme_should_propagate_errors()Andreas Kling
This is an alternative to ErrorOr<T>::release_value() that can be used when converting code to signal that we're releasing the value without error propagation as a way to move forward now. This makes these cases much easier to find later on, once more paths for error propagation are available.
2021-11-08AK: Bring AK::Error into the global namespaceAndreas Kling
2021-11-08AK: Add Error and ErrorOr<T>Andreas Kling
The goal with these is to eventually replace AK::Result, KResult and KResultOr<T> with something that works (and makes sense) in both kernel and userspace. This first cut of Error can be made from an errno code, or from a string literal (StringView)
2020-04-21AK: Remove unused Error templateAndreas Kling
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2019-07-31Add Error<>Robin Burchell
Put simply, Error<> is a way of forcing error handling onto an API user. Given a function like: bool might_work(); The following code might have been written previously: might_work(); // but what if it didn't? The easy way to work around this is of course to [[nodiscard]] might_work. But this doesn't work for more complex cases like, for instance, a hypothetical read() function which might return one of _many_ errors (typically signalled with an int, let's say). int might_read(); In such a case, the result is often _read_, but not properly handled. Like: return buffer.substr(0, might_read()); // but what if might_read returned an error? This is where Error<> comes in: typedef Error<int, 0> ReadError; ReadError might_read(); auto res = might_read(); if (might_read.failed()) { switch (res.value()) { case EBADF: ... } } Error<> uses clang's consumable attributes to force failed() to be checked on an Error instance. If it's not checked, then you get smacked.