Discuss error handling frameworks such as std::expected or Boost.LEAF
Open, Needs TriagePublic

Description

Many languages have the concept that operations return a special type that can either be the desired output value or another type that represents an error. For example a function loadPlugin(String) would return Either<PluginObject, String> where String is an error message.

For C++ this is proposed as std::expected. However the standardization is not finalized and a (usable) resolution is years in the future.

Questions are:

  • Do we want to apply this paradigm in our code?
  • If yes, how is it going to be implemented?
    • Use https://github.com/TartanLlama/expected, potentially wrapped in/renamed to KExpected in KCoreAddons. Advantage would be that we can start using it early
    • Qt also expressed interest in having this, but that's a bit uncertain and material for 6.x
    • Use custom struct solutions.
ervin moved this task from Needs Input to In Discussion on the KF6 board.Mar 28 2021, 2:33 PM

Another approach to error handling would be https://github.com/boostorg/leaf

skelly added a subscriber: skelly.Mar 28 2021, 2:58 PM

I've found that one of the disadvantages of std::expected is that it causes the error type to appear in your API meaning it's

  • harder to change
  • it's harder to call other functions which return expecteds with different expected types or error types.

One thing that's possible to partly mitigate that is to use std::error_code as the error type everywhere.

LEAF takes a different approach because it does not make the error type part of the return type, so I think if we want to have a solution across all of frameworks, we should investigate these issues and alternatives to std::expected such as LEAF.

ervin moved this task from In Discussion to Backlog on the KF6 board.Mar 28 2021, 3:28 PM
skelly renamed this task from Discuss error handling a la std::expected to Discuss error handling frameworks such as std::expected or Boost.LEAF.Mar 28 2021, 3:28 PM
alex added a subscriber: alex.Aug 21 2021, 9:47 AM

We settled for another solution in the plugin loading.

Can this task be considered done or is it actionable in any way?

alex moved this task from Backlog to Optional/Low Priority on the KF6 board.Sep 10 2021, 3:26 PM

another library that tackles this issue:

https://github.com/bitwizeshift/result

this one is starting to be the "industry standard" error handling library for c++ I believe.