Skip to content

Commit

Permalink
Move Expected/Error from internal -> core (#263)
Browse files Browse the repository at this point in the history
Authors:
  - Ryan Olson (https://github.com/ryanolson)

Approvers:
  - Michael Demoret (https://github.com/mdemoret-nv)

URL: #263
  • Loading branch information
ryanolson authored Jan 13, 2023
1 parent 7439865 commit 57abd43
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,19 @@

#pragma once

#include "mrc/core/std23_expected.hpp" // IWYU pragma: export
#include "mrc/core/expected.hpp" // IWYU pragma: export
#include "mrc/utils/macros.hpp"
#include "mrc/utils/string_utils.hpp" // IWYU pragma: export

namespace mrc::internal {
namespace mrc {

enum class ErrorCode
{
Internal,
Fatal,
ChannelClosed,
};

class Error;

// todo(#219) - update tidy to allow the following typedef
using UnexpectedError = std23::unexpected<Error>; // NOLINT

class Error final : public std::exception
{
Error(ErrorCode type) : m_code(type) {}
Expand All @@ -42,9 +38,9 @@ class Error final : public std::exception

public:
template <typename... ArgsT>
static UnexpectedError create(ArgsT&&... args)
static auto create(ArgsT&&... args) -> decltype(auto)
{
return UnexpectedError(Error(std::forward<ArgsT>(args)...));
return unexpected(Error(std::forward<ArgsT>(args)...));
}

DEFAULT_MOVEABILITY(Error);
Expand All @@ -70,7 +66,7 @@ class Error final : public std::exception
};

template <typename T = void>
using Expected = std23::expected<T, Error>; // NOLINT
using Expected = expected<T, Error>; // NOLINT

#define MRC_CHECK(condition) \
if (!(condition)) \
Expand All @@ -92,4 +88,4 @@ using Expected = std23::expected<T, Error>; // NOLINT
throw expected.error(); \
}

} // namespace mrc::internal
} // namespace mrc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#include <utility>
#include <variant>

namespace std23 {
namespace mrc {

// clang-format off
// NOLINTBEGIN(*)
Expand Down Expand Up @@ -1478,4 +1478,4 @@ class expected<void, E> {
// NOLINTEND(*)
// clang-format on

} // namespace std23
} // namespace mrc
6 changes: 3 additions & 3 deletions cpp/mrc/include/mrc/coroutines/ring_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

#pragma once

#include "mrc/core/std23_expected.hpp"
#include "mrc/core/expected.hpp"
#include "mrc/coroutines/schedule_policy.hpp"
#include "mrc/coroutines/thread_local_context.hpp"
#include "mrc/coroutines/thread_pool.hpp"
Expand Down Expand Up @@ -243,13 +243,13 @@ class RingBuffer
/**
* @return The consumed element or std::nullopt if the read has failed.
*/
auto await_resume() -> std23::expected<ElementT, RingBufferOpStatus>
auto await_resume() -> mrc::expected<ElementT, RingBufferOpStatus>
{
ThreadLocalContext::resume_thread_local_context();

if (m_stopped)
{
return std23::unexpected<RingBufferOpStatus>(RingBufferOpStatus::Stopped);
return mrc::unexpected<RingBufferOpStatus>(RingBufferOpStatus::Stopped);
}

return std::move(m_e);
Expand Down
2 changes: 1 addition & 1 deletion cpp/mrc/src/internal/control_plane/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
#pragma once

#include "internal/control_plane/client/instance.hpp" // IWYU pragma: keep
#include "internal/expected.hpp"
#include "internal/grpc/client_streaming.hpp"
#include "internal/grpc/stream_writer.hpp"
#include "internal/resources/partition_resources_base.hpp"
#include "internal/service.hpp"

#include "mrc/core/error.hpp"
#include "mrc/node/source_channel.hpp"
#include "mrc/protos/architect.grpc.pb.h"
#include "mrc/protos/architect.pb.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

#include "internal/control_plane/client.hpp"
#include "internal/control_plane/client/instance.hpp"
#include "internal/expected.hpp"
#include "internal/runnable/resources.hpp"
#include "internal/ucx/resources.hpp"
#include "internal/ucx/worker.hpp"
#include "internal/utils/contains.hpp"

#include "mrc/core/error.hpp"
#include "mrc/core/task_queue.hpp"
#include "mrc/protos/architect.pb.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#include "internal/control_plane/client/state_manager.hpp"

#include "internal/control_plane/client.hpp"
#include "internal/expected.hpp"
#include "internal/runnable/resources.hpp"

#include "mrc/core/error.hpp"
#include "mrc/node/edge_builder.hpp"
#include "mrc/node/rx_sink.hpp"
#include "mrc/node/source_channel.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

#include "internal/control_plane/client.hpp"
#include "internal/control_plane/client/instance.hpp"
#include "internal/expected.hpp"
#include "internal/service.hpp"
#include "internal/utils/contains.hpp"

#include "mrc/core/error.hpp"
#include "mrc/protos/architect.pb.h"

#include <boost/fiber/future/promise.hpp>
Expand Down
2 changes: 1 addition & 1 deletion cpp/mrc/src/internal/control_plane/proto_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#pragma once

#include "internal/expected.hpp"
#include "mrc/core/error.hpp"

#include <google/protobuf/any.pb.h>

Expand Down
4 changes: 2 additions & 2 deletions cpp/mrc/src/internal/control_plane/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,11 @@ void Server::do_handle_event(event_t&& event)
DVLOG(10) << "event.ok failed; close stream";
drop_stream(event.stream);
}
} catch (const std23::bad_expected_access<Error>& e)
} catch (const mrc::bad_expected_access<Error>& e)
{
LOG(ERROR) << "bad_expected_access: " << e.error().message();
on_fatal_exception();
} catch (const UnexpectedError& e)
} catch (const mrc::unexpected<Error>& e)
{
LOG(ERROR) << "unexpected: " << e.value().message();
on_fatal_exception();
Expand Down
2 changes: 1 addition & 1 deletion cpp/mrc/src/internal/control_plane/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
#pragma once

#include "internal/control_plane/server/connection_manager.hpp"
#include "internal/expected.hpp"
#include "internal/grpc/server.hpp"
#include "internal/grpc/server_streaming.hpp"
#include "internal/service.hpp"

#include "mrc/core/error.hpp"
#include "mrc/node/queue.hpp"
#include "mrc/protos/architect.grpc.pb.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#pragma once

#include "internal/control_plane/server/versioned_issuer.hpp"
#include "internal/expected.hpp"
#include "internal/grpc/server_streaming.hpp"

#include "mrc/core/error.hpp"
#include "mrc/types.hpp"

#include <cstddef>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

#include "internal/control_plane/server/tagged_issuer.hpp"
#include "internal/control_plane/server/versioned_issuer.hpp"
#include "internal/expected.hpp"

#include "mrc/core/error.hpp"
#include "mrc/types.hpp"

#include <cstdint>
Expand Down
3 changes: 1 addition & 2 deletions cpp/mrc/src/tests/test_expected.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "internal/expected.hpp"
#include "mrc/core/error.hpp"

#include <glog/logging.h>
#include <gtest/gtest.h>
Expand All @@ -26,7 +26,6 @@
#include <utility>

using namespace mrc;
using namespace mrc::internal;

class TestExpected : public ::testing::Test
{};
Expand Down

0 comments on commit 57abd43

Please sign in to comment.