You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@mesos.apache.org by "Benjamin Bannier (JIRA)" <ji...@apache.org> on 2016/10/21 13:02:58 UTC
[jira] [Created] (MESOS-6439) Try::error returns a std::string
instead of an Error
Benjamin Bannier created MESOS-6439:
---------------------------------------
Summary: Try::error returns a std::string instead of an Error
Key: MESOS-6439
URL: https://issues.apache.org/jira/browse/MESOS-6439
Project: Mesos
Issue Type: Improvement
Components: stout
Reporter: Benjamin Bannier
{{Try}}'s with implicit error types ({{E = Error}}) return a {{std::string}} for {{error}} instead of some error type. This is explained in the code with the following comment:
{code}
// NOTE: This function is intended to return the error of type `E`.
// However, we return a `std::string` if `E` == `Error` since that's what it
// used to return, and it's the only data that `Error` holds anyway.
const typename std::conditional<
std::is_same<E, Error>::value, std::string, E>::type& error() const
{code}
It seems that always returning an {{E}} here and possibly allowing implicit conversions of {{Error}} to {{std::string}} would be a cleaner solution. It seems this would simpler composition, e.g.,
{code}
Try<Nothing> foo() {
const Try<int> x = bar();
if (x.isError()) {
return x.error(); // ATM: return Error(x.error());
}
// work with x's value
// ...
}
{code}
ATM {{Try::error}} might not actually be an {{Error}}, but instead some implementation detail of it, requiring most users to manually disambiguate with a temporary at the call site.
If we'd implement this change we should probably also make a sweep of the code base.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)