BoundaryML/baml · error

No tracer found

Error message

No tracer found

What it means

get_tracer assumes the internal tracers map always holds at least one tracer and unwraps its first entry on the wasm32 target. If the map is empty (no tracer was ever created, or all were cleared), expect panics with 'No tracer found'. It is a guard against an invariant violation in tracer lifecycle management.

Source

Thrown at engine/baml-runtime/src/lib.rs:224

                }
            }
            // Config changed, clear all and insert new
            self.tracers.clear();
            let new_tracer = Arc::new(
                BamlTracer::new(None, filtered.clone().into_iter())
                    .expect("Failed to create BamlTracer"),
            );
            self.tracers.insert(key, new_tracer.clone());
            new_tracer
        }
    }

    /// Get the current tracer (the only one in the map, if any).
    pub fn get_tracer(&self) -> Arc<BamlTracer> {
        #[cfg(target_arch = "wasm32")]
        {
            let tracers = self.tracers.lock().unwrap();
            tracers.values().next().expect("No tracer found").clone()
        }
        #[cfg(not(target_arch = "wasm32"))]
        {
            self.tracers.iter().next().expect("No tracer found").clone()
        }
    }
}

cfg_if::cfg_if!(
    if #[cfg(target_arch = "wasm32")] {
        type DashMap<K, V> = std::sync::Arc<std::sync::Mutex<std::collections::HashMap<K, V>>>;
    } else {
        use dashmap::DashMap;
    }
);

/// RAII guard that ensures both TraceEvent::new_function_end and finish_baml_call
/// are properly called, even if the function returns early due to an error.

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Ensure get_or_create_tracer is called (and succeeds) before any get_tracer call
  2. Return an Option/Result from get_tracer instead of expect so callers can handle the empty case
  3. Check application initialization order so the runtime is fully constructed before tracing APIs are used
  4. Fix any failing tracer creation path that clears the map but fails to insert a replacement
Defensive patterns

Strategy: validation

Validate before calling

// wasm caller check before use
if tracers_len(tracer_map) == 0 {
    tracer = get_or_create_tracer(config);
}

Prevention

When it happens

Trigger: Calling BamlRuntime::get_tracer on wasm32 when the tracers mutex map contains no entries — i.e. get_or_create_tracer was never called or the map was cleared by a config-change path that failed before inserting a new tracer.

Common situations: Accessing the tracer before runtime initialization completes; a prior get_or_create_tracer panicked and left the map empty; single-page-app reloads that recreate runtime state out of order.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/b7d334b8a4ce79f4. Report an issue: GitHub.