Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export RecordingStreamError #3777

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ doc-valid-idents = [
"sRGB",
"sRGBA",
"WebGL",
"WebSocket",
"WebSockets",
]
4 changes: 3 additions & 1 deletion crates/re_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
17 changes: 9 additions & 8 deletions crates/re_sdk/src/recording_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error + Send + Sync>,

/// 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),
}
Expand Down Expand Up @@ -343,8 +348,7 @@ impl RecordingStreamBuilder {
) -> RecordingStreamResult<RecordingStream> {
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");
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 14 additions & 2 deletions crates/re_sdk/src/web_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +35,7 @@ impl WebViewerSink {
bind_ip: &str,
web_port: WebViewerServerPort,
ws_port: RerunServerPort,
) -> anyhow::Result<Self> {
) -> Result<Self, WebViewerSinkError> {
// 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,
Expand Down Expand Up @@ -114,7 +126,7 @@ pub fn new_sink(
bind_ip: &str,
web_port: WebViewerServerPort,
ws_port: RerunServerPort,
) -> anyhow::Result<Box<dyn crate::sink::LogSink>> {
) -> Result<Box<dyn crate::sink::LogSink>, WebViewerSinkError> {
Ok(Box::new(WebViewerSink::new(
open_browser,
bind_ip,
Expand Down
1 change: 1 addition & 0 deletions crates/re_web_viewer_server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")]
Expand Down
1 change: 1 addition & 0 deletions crates/re_ws_comms/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")]
Expand Down
1 change: 1 addition & 0 deletions scripts/clippy_wasm/clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ doc-valid-idents = [
"sRGB",
"sRGBA",
"WebGL",
"WebSocket",
"WebSockets",
"..",
]
Loading