diff --git a/examples/tic-tac-toe-gui/src/main.rs b/examples/tic-tac-toe-gui/src/main.rs index 1544576..6ec6d87 100644 --- a/examples/tic-tac-toe-gui/src/main.rs +++ b/examples/tic-tac-toe-gui/src/main.rs @@ -85,7 +85,7 @@ impl TicTacToeApp { // Establish a closure that handles the incoming messages self.waku.ctx.waku_set_event_callback(my_closure).expect("set event call back working"); - // Subscribe to desired topic + // Subscribe to desired topic using the relay protocol // self.waku.relay_subscribe(&self.game_topic.to_string()).expect("waku should subscribe"); let content_topic = WakuContentTopic::new("waku", "2", "tictactoegame", Encoding::Proto); diff --git a/waku-bindings/src/node/context.rs b/waku-bindings/src/node/context.rs index c9e47a8..1d41273 100644 --- a/waku-bindings/src/node/context.rs +++ b/waku-bindings/src/node/context.rs @@ -10,12 +10,21 @@ pub struct WakuNodeContext { impl WakuNodeContext { pub fn new(obj_ptr: *mut c_void) -> Self { - Self { + let me = Self { obj_ptr: obj_ptr, - msg_observer: Arc::new(Mutex::new(Box::new(|_response| { - println!("msg observer not set") - }))), - } + msg_observer: Arc::new(Mutex::new(Box::new(|_| {}))), + }; + + // By default we set a callback that will panic if the user didn't specify a valid callback. + // And by valid callback we mean a callback that can properly handle the waku events. + me.waku_set_event_callback(WakuNodeContext::panic_callback) + .expect("correctly set default callback"); + me + } + + // default callback that does nothing. A valid callback should be set + fn panic_callback(_response: LibwakuResponse) { + panic!("callback not set. Please use waku_set_event_callback to set a valid callback") } pub fn get_ptr(&self) -> *mut c_void { diff --git a/waku-bindings/tests/node.rs b/waku-bindings/tests/node.rs index 3d7a314..a41fa98 100644 --- a/waku-bindings/tests/node.rs +++ b/waku-bindings/tests/node.rs @@ -32,7 +32,7 @@ async fn test_echo_messages( content_topic: WakuContentTopic, ) -> Result<(), String> { // setting a naïve event handler to avoid appearing ERR messages in logs - node1.ctx.waku_set_event_callback(&|_| {}); + let _ = node1.ctx.waku_set_event_callback(&|_| {}); let rx_waku_message: Arc> = Arc::new(Mutex::new(WakuMessage::default()));