Skip to content

Commit

Permalink
Re-export RecordingStreamError (#3777)
Browse files Browse the repository at this point in the history
* Closes #3735

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/3777) (if
applicable)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG

- [PR Build Summary](https://build.rerun.io/pr/3777)
- [Docs
preview](https://rerun.io/preview/a7dd4dce56f3fec82e3ab5e38c1f3f38606e249c/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/a7dd4dce56f3fec82e3ab5e38c1f3f38606e249c/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://ref.rerun.io/dev/bench/)
- [Wasm size tracking](https://ref.rerun.io/dev/sizes/)
  • Loading branch information
emilk authored Oct 10, 2023
1 parent 979e0ba commit 3dfc221
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 11 deletions.
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",
"..",
]

0 comments on commit 3dfc221

Please sign in to comment.