I would have expected for {}
to return an empty error message. Is there any way to avoid this confusion at compile time?
Yeah @MarcoFalke, my bad here, I shouldn’t had reviewed the PR before sleep…
As we internally use an std::variant
, and the first element is the bilingual_str
. The {}
will indeed initialize the variant with an empty error message.
What I tried to say on the message is that I don’t see how empty error strings are useful. The caller cannot know where/why the function failed (which is the main purpose of returning an error string in the first place).
Thinking out loud without test it:
Probably we could prevent this behavior by removing the empty constructor or by asserting that an error string cannot be empty.
I think the silent conversion of bilingual_str into errors is an anti-feature. Not every translated string is necessarily an error string, and the conversion makes it not possible to use a BResult<bilingual_str> type that returns a normal translated string. #25665 improves this by adding an explicit error contructor
You know, the initial version that did for the generic CallResult
was actually implemented in that way. I was using an OperationResult<T, E> ErrorOut(string)
helper function instead of the silent conversion.
I have 25665 on my review list 👍🏼 . The last time that I checked it (brief check, thus why I haven’t commented yet), I wasn’t so sure about the internal std:.variant removal because every result was going to have the succeed object initialized AND the errors AND warnings in memory. And conceptually, a function can succeed OR fail. Not both.
But.. will comment there soon :). Need to finish up few other reviews first. Been focused on the nice, and long, #24914 lately.