Skip to content

[BUG] Ctrl+C Handler Uses expect() Which Can Panic #95

@olddev94

Description

@olddev94

Project

vgrep

Description

The file watcher in src/watcher.rs line 65 uses .expect() when setting up the Ctrl+C handler. This can panic and crash the application when running in environments where signal handlers cannot be set (e.g., certain containerized environments, non-TTY contexts, or when another handler is already registered).

Error Message

thread 'main' panicked at 'Error setting Ctrl+C handler: ...'

Debug Logs

System Information

- Bounty Version: 0.1.0
- OS: Ubuntu 24.04 LTS
- Rust: 1.75+

Screenshots

No response

Steps to Reproduce

  1. Run vgrep watch in a non-TTY environment:
    echo "" | vgrep watch
    or
    vgrep watch < /dev/null
  2. In some environments, this will panic when trying to set the signal handler

Expected Behavior

The application should handle signal handler setup failures gracefully:

  1. Log a warning that graceful shutdown won't work
  2. Continue running without the signal handler
  3. Document alternative ways to stop the watcher (kill -9, etc.)

Actual Behavior

Application panics and terminates if signal handler cannot be set, preventing the watcher from running at all in certain environments.

Additional Context

Environments where this might fail:

  • Docker containers without TTY (docker run without -it)
  • CI/CD pipelines
  • Background service execution
  • Environments with existing signal handlers
  • Some Windows configurations

The ctrlc crate itself documents that set_handler can fail in various scenarios. Using .expect() is overly strict for what is essentially a convenience feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingvalidValid issuevgrep

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions