Skip to content

bug: potential runtime crashes from unwrap/expect usage #41

@Ishita-190

Description

@Ishita-190

Files:

Several runtime and UI code paths rely on unwrap(), expect(), or other panic-based error handling. These constructs terminate execution when encountering unexpected Err or None values.

Current Behavior:

  • Startup logic unwraps optional engine state, which may terminate execution if initialization fails.
  • UI code uses expect("... mutex poisoned"), causing additional panics if a mutex becomes poisoned after a prior failure.
  • Parser and SSML logic unwrap parsing results that may depend on external or user-provided input.
  • Some tests use raw unwrap() calls that produce less informative failures.

Expected Behavior:

  • Runtime code should propagate errors using Result instead of panicking.
  • Missing configuration or state should produce logged, recoverable errors.
  • UI paths should recover safely from poisoned mutexes.
  • Parsing failures should return structured errors rather than terminating execution.

Proposed Changes:

  1. In node-hub/dora-funasr-nano-mlx/src/main.rs:

Current:

let engine = engine.as_mut().unwrap();

Proposed:

let engine = match engine.as_mut() {
    Some(e) => e,
    None => {
        log::error!("Engine unexpectedly missing after attempted initialization");
        send_log(&mut node, "ERROR", "Engine not available")?;
        continue;
    }
};
  1. In apps/mofa-asr/src/screen/mod.rs:

Current:

let mut guard = controller.lock().expect("ChatController mutex poisoned");

Proposed:

let mut guard = match controller.lock() {
    Ok(g) => g,
    Err(poisoned) => {
        log::warn!("ChatController mutex poisoned; recovering inner state");
        poisoned.into_inner()
    }
};
  1. In mofa-dora-bridge/src/parser.rs:

Current:

let parsed = DataflowParser::parse_string(yaml, PathBuf::from("test.yml")).unwrap();

Proposed:

let parsed = DataflowParser::parse_string(yaml, PathBuf::from("test.yml"))
    .expect("DataflowParser failed to parse a valid test YAML; check parser changes");
  1. In node-hub/dora-gpt-sovits-mlx/src/ssml.rs:

Current:

let result = parse_ssml("<speak>hello world</speak>").unwrap();

Proposed:

let result = parse_ssml("<speak>hello world</speak>")
    .expect("parse_ssml should parse simple <speak> content");

Would like to work on a PR for this if the maintainers approve

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions