Skip to content

Conversation

KitsuneRal
Copy link
Member

@KitsuneRal KitsuneRal commented Oct 7, 2025

In essence, this PR makes JobHandle to produce a QFuture<std::expected<...>> thing if you want to propagate errors in the same package as responses. When working directly with JobHandle you can simply use 2-arg then(); but if you want to take a QFuture out of JobHandle and only carry the result after letting the job self-destruct, well, here's a way.

It is still a bit experimental but after trying it on a couple of methods from Connection I think it makes sense. In Quaternion, I have a blanket error handling, the legacy of very early times - whichever requestFailed() occurred, a single handler processes it. Although all new requests automatically get this blanket error handling, I can't specialise it for specific requests. This PR allows me to add error reporting and handling on the spot without having to stick with JobHandles. And actually, one such case even pre-dates this PR: Room::upgrade() already returns QFuture<std::expected<...>> and using that is very organic I believe.

Opinions welcome.

...namely, member functions of the respective job class, or of the
result object.
toFutureExpected() doesn't have any users yet.
If the return types are different, then() will now return a future
wrapping a std::expected object, instead of failing the build.
With 2-arg then() combining outcomes into a std::expected its implementation is primitive as can be.
It doesn't have its users yet though, so tread carefully.
The two facilities to make working with std::expected less verbose. E.g.
you can now use `const Expected_Class auto&` or even `JobResult<Room *>`
instead of `std::expected<Room *, BaseJob::Status>` for the accepted
type.
getDirectChat() has now got the more robust tryGetDirectChat()
counterpart; and joinAndGetRoom(), being effectively unused outside of
Quotient, changed its signature on the spot.
@KitsuneRal KitsuneRal added the enhancement A feature or change request for the library label Oct 7, 2025
@github-project-automation github-project-automation bot moved this to In work in libQuotient 1 Oct 7, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 7, 2025

@KitsuneRal KitsuneRal changed the title Better error exposure around JobHandle Better error exposure around JobHandle (aka QFuture<std::expected<>>) Oct 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement A feature or change request for the library

Projects

Status: In work

Development

Successfully merging this pull request may close these issues.

1 participant