Skip to content

Commit

Permalink
Clean up warnings printed when rr.init hasn't been called (#2209)
Browse files Browse the repository at this point in the history
The recording handle work changed the behavior of some of our warnings
when calling a log API without having called `rr.init`.

Before:
```
[2023-05-25T09:09:33Z WARN  re_sdk::global] There is no currently active Data recording available for the current thread (ThreadId(1)): have you called `set_global()` and/or `set_thread_local()` first?
WARNING:rerun:Rerun is disabled - log_text_box() call ignored
```

After:
```
WARNING:rerun:Rerun is disabled - log_text_box() call ignored. You must call rerun.init before using log APIs.
```

PR Build Summary: https://build.rerun.io/pr/2209
  • Loading branch information
jleibs authored May 25, 2023
1 parent 5248f1f commit c3f9a5f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
27 changes: 27 additions & 0 deletions crates/re_sdk/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,33 @@ impl RecordingStream {
rec
}

// Internal implementation of `get()` that doesn't print a warning if no recording is found.
// Used from python-bridge.
#[inline]
#[doc(hidden)]
pub fn get_quiet(
which: RecordingType,
overrides: Option<RecordingStream>,
) -> Option<RecordingStream> {
let rec = overrides.or_else(|| {
Self::get_any(RecordingScope::ThreadLocal, which)
.or_else(|| Self::get_any(RecordingScope::Global, which))
});

if rec.is_none() {
// NOTE: This is the one and only place where a warning about missing active recording
// should be printed, don't stutter!
re_log::debug_once!(
"There is no currently active {which} recording available \
for the current thread ({:?}): have you called `set_global()` and/or \
`set_thread_local()` first?",
std::thread::current().id(),
);
}

rec
}

// --- Global ---

/// Returns the currently active recording of the specified type in the global scope, if any.
Expand Down
5 changes: 4 additions & 1 deletion rerun_py/rerun_sdk/rerun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,10 @@ def start_web_viewer_server(port: int = 0) -> None:
"""

if not bindings.is_enabled():
logging.warning("Rerun is disabled - self_host_assets() call ignored")
logging.warning(
"Rerun is disabled - start_web_viewer_server() call ignored. You must call rerun.init before starting the"
+ " web viewer server."
)
return

bindings.start_web_viewer_server(port)
4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/log/log_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
recording = RecordingStream.to_native(kwargs.get("recording"))
if not bindings.is_enabled(recording):
# NOTE: use `warnings` which handles runtime deduplication.
warnings.warn(f"Rerun is disabled - {func.__name__}() call ignored")
warnings.warn(
f"Rerun is disabled - {func.__name__}() call ignored. You must call rerun.init before using log APIs."
)
return

if rerun.strict_mode():
Expand Down
2 changes: 1 addition & 1 deletion rerun_py/rerun_sdk/rerun/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def save(path: str, recording: Optional[RecordingStream] = None) -> None:
"""

if not bindings.is_enabled():
logging.warning("Rerun is disabled - save() call ignored")
logging.warning("Rerun is disabled - save() call ignored. You must call rerun.init before saving a recording.")
return

recording = RecordingStream.to_native(recording)
Expand Down
4 changes: 2 additions & 2 deletions rerun_py/src/python_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ fn get_recording_id(recording: Option<&PyRecordingStream>) -> Option<String> {
/// specified recording otherwise, if any.
#[pyfunction]
fn get_data_recording(recording: Option<&PyRecordingStream>) -> Option<PyRecordingStream> {
RecordingStream::get(
RecordingStream::get_quiet(
rerun::RecordingType::Data,
recording.map(|rec| rec.0.clone()),
)
Expand Down Expand Up @@ -408,7 +408,7 @@ fn set_thread_local_data_recording(
/// specified recording otherwise, if any.
#[pyfunction]
fn get_blueprint_recording(overrides: Option<&PyRecordingStream>) -> Option<PyRecordingStream> {
RecordingStream::get(
RecordingStream::get_quiet(
rerun::RecordingType::Blueprint,
overrides.map(|rec| rec.0.clone()),
)
Expand Down

0 comments on commit c3f9a5f

Please sign in to comment.