Skip to content

Panic in src/scanning/mod.rs: Unhandled network errors causing application crash #13

Description

@lukasaltnotclear-art

Description:
The scanner panics and crashes whenever it encounters network errors like Connection timed out or Connection refused. This happens because of an unhandled .unwrap() call in src/scanning/mod.rs.

Log output:

Plaintext
thread 'tokio-rt-worker' panicked at src/scanning/mod.rs:16:59:
called Result::unwrap() on an Err value: Os { code: 110, kind: TimedOut, message: "Connection timed out" }

Proposed Fix:
Since I am not an experienced Rust developer, I asked an AI for assistance to make the scanner more resilient. Replacing the .unwrap() with proper error handling solves the crash.

Here is the suggested change in src/scanning/mod.rs:

// Replace this:
let mut stream = TcpStream::connect(socket).await.unwrap();

// With this:
let mut stream = TcpStream::connect(socket)
.await
.map_err(|e| anyhow::anyhow!("Connection failed: {}", e))?;

This ensures that network errors are caught as anyhow::Result instead of panicking the entire application.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions