As part of our common error handling pattern, we occasionally need to fallible operations in what would be a class constructor. However, since constructors can't have a custom return type, we instead realize this by creating a static member function that returns ErrorOr<>
or Error<NonnullOwnPtr<>>
depending on the type that is being constructed.
Over time, this has resulted in a multiple of different function names, including (but not limited to) create
, construct
and try_create
. To make this easier on the developer, create
has been chosen as the new standard name for fallible constructors and all existing ones should be migrated to the new name as well. This includes the following:
File::open
, Gfx::Bitmap::try_load_from_file
, etc.)create
or try_create
try_
prefix where no non-fallible function without the prefix exists already (similar to #17131)Common sense and/or additional discussion should be applied where the above either ambiguous or the function naming might be dictated due to other circumstances.
ByteBuffer::create_zeroed
and ByteBuffer::create_unitialized
stay as-is, as the first part is already correct and the second part denotes the difference between either function.Gfx::Bitmap::try_create
loses the try_
prefix, since there is no nonfallible Gfx::Bitmap::create
.Gfx::Bitmap::try_load_from_file
loses the try_
prefix but retains the rest, since we are specifically loading the bitmap from a file instead of just creating an (empty) bitmap and there is no nonfallible Gfx::Bitmap::load_from_file
.FixedMemoryStream::construct
gets renamed to FixedMemoryStream::create
since it does nothing but calling the constructor.Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too