diff --git a/clippy.toml b/clippy.toml index 9698ade11975..2278963d009b 100644 --- a/clippy.toml +++ b/clippy.toml @@ -81,5 +81,6 @@ doc-valid-idents = [ "sRGB", "sRGBA", "WebGL", + "WebSocket", "WebSockets", ] diff --git a/crates/re_sdk/src/lib.rs b/crates/re_sdk/src/lib.rs index ef6c130d2c0e..c5bfafe827b7 100644 --- a/crates/re_sdk/src/lib.rs +++ b/crates/re_sdk/src/lib.rs @@ -25,7 +25,9 @@ mod log_integration; // ------------- // Public items: -pub use self::recording_stream::{RecordingStream, RecordingStreamBuilder, RecordingStreamResult}; +pub use self::recording_stream::{ + RecordingStream, RecordingStreamBuilder, RecordingStreamError, RecordingStreamResult, +}; pub use re_sdk_comms::{default_flush_timeout, default_server_addr}; diff --git a/crates/re_sdk/src/recording_stream.rs b/crates/re_sdk/src/recording_stream.rs index ceb607b7ae53..5d43a727e490 100644 --- a/crates/re_sdk/src/recording_stream.rs +++ b/crates/re_sdk/src/recording_stream.rs @@ -58,14 +58,19 @@ pub enum RecordingStreamError { /// Error spawning one of the background threads. #[error("Failed to spawn background thread '{name}': {err}")] SpawnThread { + /// Name of the thread name: &'static str, - err: Box, + + /// Inner error explaining why the thread failed to spawn. + err: std::io::Error, }, + /// Failure to host a web viewer and/or Rerun server. #[cfg(feature = "web_viewer")] #[error(transparent)] - WebSink(anyhow::Error), + WebSink(#[from] crate::web_viewer::WebViewerSinkError), + /// An error that can occur because a row in the store has inconsistent columns. #[error(transparent)] DataReadError(#[from] re_log_types::DataReadError), } @@ -343,8 +348,7 @@ impl RecordingStreamBuilder { ) -> RecordingStreamResult { let (enabled, store_info, batcher_config) = self.into_args(); if enabled { - let sink = crate::web_viewer::new_sink(open_browser, bind_ip, web_port, ws_port) - .map_err(RecordingStreamError::WebSink)?; + let sink = crate::web_viewer::new_sink(open_browser, bind_ip, web_port, ws_port)?; RecordingStream::new(store_info, batcher_config, sink) } else { re_log::debug!("Rerun disabled - call to serve() ignored"); @@ -501,10 +505,7 @@ impl RecordingStreamInner { let batcher = batcher.clone(); move || forwarding_thread(info, sink, cmds_rx, batcher.tables()) }) - .map_err(|err| RecordingStreamError::SpawnThread { - name: NAME, - err: Box::new(err), - })? + .map_err(|err| RecordingStreamError::SpawnThread { name: NAME, err })? }; Ok(RecordingStreamInner { diff --git a/crates/re_sdk/src/web_viewer.rs b/crates/re_sdk/src/web_viewer.rs index 752f5a82d071..0a24ba3ef78c 100644 --- a/crates/re_sdk/src/web_viewer.rs +++ b/crates/re_sdk/src/web_viewer.rs @@ -2,6 +2,18 @@ use re_log_types::LogMsg; use re_web_viewer_server::{WebViewerServerHandle, WebViewerServerPort}; use re_ws_comms::{RerunServerHandle, RerunServerPort}; +/// Failure to host a web viewer and/or Rerun server. +#[derive(thiserror::Error, Debug)] +pub enum WebViewerSinkError { + /// Failure to host the web viewer. + #[error(transparent)] + WebViewerServer(#[from] re_web_viewer_server::WebViewerServerError), + + /// Failure to host the Rerun WebSocket server. + #[error(transparent)] + RerunServer(#[from] re_ws_comms::RerunServerError), +} + /// A [`crate::sink::LogSink`] tied to a hosted Rerun web viewer. This internally stores two servers: /// * A [`re_ws_comms::RerunServer`] to relay messages from the sink to a websocket connection /// * A [`re_web_viewer_server::WebViewerServer`] to serve the Wasm+HTML @@ -23,7 +35,7 @@ impl WebViewerSink { bind_ip: &str, web_port: WebViewerServerPort, ws_port: RerunServerPort, - ) -> anyhow::Result { + ) -> Result { // TODO(cmc): the sources here probably don't make much senseā€¦ let (rerun_tx, rerun_rx) = re_smart_channel::smart_channel( re_smart_channel::SmartMessageSource::Sdk, @@ -114,7 +126,7 @@ pub fn new_sink( bind_ip: &str, web_port: WebViewerServerPort, ws_port: RerunServerPort, -) -> anyhow::Result> { +) -> Result, WebViewerSinkError> { Ok(Box::new(WebViewerSink::new( open_browser, bind_ip, diff --git a/crates/re_web_viewer_server/src/lib.rs b/crates/re_web_viewer_server/src/lib.rs index 3576cb7a5fac..6e03322ad4e8 100644 --- a/crates/re_web_viewer_server/src/lib.rs +++ b/crates/re_web_viewer_server/src/lib.rs @@ -31,6 +31,7 @@ mod data { pub const VIEWER_WASM: &[u8] = include_bytes!("../web_viewer/re_viewer_bg.wasm"); } +/// Failure to host the web viewer. #[derive(thiserror::Error, Debug)] pub enum WebViewerServerError { #[error("Could not parse address: {0}")] diff --git a/crates/re_ws_comms/src/lib.rs b/crates/re_ws_comms/src/lib.rs index 4df6c187ab42..9ea0e0ee3da3 100644 --- a/crates/re_ws_comms/src/lib.rs +++ b/crates/re_ws_comms/src/lib.rs @@ -28,6 +28,7 @@ pub const PROTOCOL: &str = "ws"; // ---------------------------------------------------------------------------- +/// Failure to host the Rerun WebSocket server. #[derive(thiserror::Error, Debug)] pub enum RerunServerError { #[error("Failed to bind to WebSocket port {0}: {1}")] diff --git a/scripts/clippy_wasm/clippy.toml b/scripts/clippy_wasm/clippy.toml index 3b458a6da4b0..3fee57b67a67 100644 --- a/scripts/clippy_wasm/clippy.toml +++ b/scripts/clippy_wasm/clippy.toml @@ -56,6 +56,7 @@ doc-valid-idents = [ "sRGB", "sRGBA", "WebGL", + "WebSocket", "WebSockets", "..", ]