You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2018/01/11 00:36:11 UTC

[3/5] mesos git commit: Returned `Try` from `protobuf::read(path)` rather than `Result`.

Returned `Try<T>` from `protobuf::read(path)` rather than `Result<T>`.

The path version of `protobuf::read` used to return `Result<T>` and
returned `None` only when the file is empty (`ignorePartial` is always
`false`). The `None` return represents EOF for the "streaming" version
of `protobuf::read` that takes an FD, but for the path version an empty
file when we expected to read `T` is simply an error. Thus, we map the
`None` return to an `Error` for the path version and return a `Try<T>`.

Review: https://reviews.apache.org/r/65021


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f955f8ea
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f955f8ea
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f955f8ea

Branch: refs/heads/1.5.x
Commit: f955f8ea090fa2e947336a5cf8e2f1deca13ee66
Parents: 78695e4
Author: Michael Park <mp...@apache.org>
Authored: Fri Jan 5 16:49:53 2018 -0800
Committer: Michael Park <mp...@apache.org>
Committed: Wed Jan 10 16:35:58 2018 -0800

----------------------------------------------------------------------
 3rdparty/stout/include/stout/protobuf.hpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f955f8ea/3rdparty/stout/include/stout/protobuf.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/protobuf.hpp b/3rdparty/stout/include/stout/protobuf.hpp
index f00a048..01d7581 100644
--- a/3rdparty/stout/include/stout/protobuf.hpp
+++ b/3rdparty/stout/include/stout/protobuf.hpp
@@ -340,7 +340,7 @@ Result<T> read(int_fd fd, bool ignorePartial = false, bool undoFailed = false)
 // A wrapper function that wraps the above read() with open and
 // closing the file.
 template <typename T>
-Result<T> read(const std::string& path)
+Try<T> read(const std::string& path)
 {
   Try<int_fd> fd = os::open(
       path,
@@ -358,7 +358,13 @@ Result<T> read(const std::string& path)
   // read(). Also an unsuccessful close() doesn't affect the read.
   os::close(fd.get());
 
-  return result;
+  if (result.isSome()) {
+    return result.get();
+  }
+
+  // `read(fd)` returning `None` here means that the file is empty.
+  // Since this is a partial read of `T`, we report it as an error.
+  return Error(result.isError() ? result.error() : "Found an empty file");
 }