monarch_rdma/errors.rs
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9//! Typed error returned by the RDMA manager owner.
10
11use serde::Deserialize;
12use serde::Serialize;
13use typeuri::Named;
14
15/// A typed initialization failure returned by the RDMA manager owner.
16///
17/// This is the wire error carried by the owner's replies
18/// (`Result<(), RdmaInitError>`), not a user-facing exception type — a
19/// separate PyO3 binding maps it to a catchable Python exception.
20#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Named)]
21pub enum RdmaInitError {
22 /// The manager's `init()` reported a failure.
23 InitFailed(String),
24 /// Spawning the manager (or casting to it) failed.
25 SpawnFailed(String),
26 /// A supervision failure was attributed to the manager.
27 Supervision(String),
28}
29wirevalue::register_type!(RdmaInitError);
30
31#[cfg(test)]
32mod tests {
33 use wirevalue::Any;
34
35 use super::*;
36
37 #[test]
38 fn serde_round_trip_each_variant() {
39 for e in [
40 RdmaInitError::InitFailed("init failed".to_string()),
41 RdmaInitError::SpawnFailed("spawn failed".to_string()),
42 RdmaInitError::Supervision("supervision".to_string()),
43 ] {
44 let serialized: Any = Any::serialize(&e).unwrap();
45 let decoded: RdmaInitError = serialized.deserialized().unwrap();
46 assert_eq!(decoded, e);
47 }
48 }
49
50 // Compile-only: `Result<(), RdmaInitError>` must be a `RemoteMessage` so it
51 // can cross the owner's reply `OncePort` (the manager is remote).
52 fn assert_remote_message<T: hyperactor::RemoteMessage>() {}
53
54 #[test]
55 fn result_rdma_init_error_is_remote_message() {
56 assert_remote_message::<Result<(), RdmaInitError>>();
57 }
58}