diff options
| author | diogo464 <[email protected]> | 2025-06-19 09:40:05 +0100 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-06-19 09:40:05 +0100 |
| commit | 03793fad36480273ebd702e80f41f4baf513647c (patch) | |
| tree | 151c25af837aa0c42fb596dcc112dade55ff1f89 /tests | |
| parent | 2bdfafbfe14c300b63a7659e8ded45bad42c8208 (diff) | |
Implement PidFileReadError enum for better error handling
- Add PidFileReadError enum with FileNotFound, FileInvalid, and IoError variants
- Implement Display and Error traits for proper error handling
- Update PidFile::read_from_file() to return Result<PidFile, PidFileReadError>
- Update all call sites to handle specific error types:
- is_process_running(): Handle FileNotFound/FileInvalid as "not running"
- stop_daemon(): Handle FileNotFound as "not running", FileInvalid as cleanup needed
- list_daemons(): Handle FileInvalid with specific error messages
- status_daemon(): Handle FileNotFound as "NOT FOUND", FileInvalid as detailed error
- clean_orphaned_files(): Handle FileInvalid as cleanup candidate
- Remove redundant Path::exists() checks (error type provides this info)
- Fix test timing issue by adding sleep in test_run_creates_files
- More idiomatic Rust error handling with specific error types
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/cli.rs | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/tests/cli.rs b/tests/cli.rs index e99e876..2903f61 100644 --- a/tests/cli.rs +++ b/tests/cli.rs | |||
| @@ -57,6 +57,9 @@ fn test_run_creates_files() { | |||
| 57 | assert!(temp_dir.path().join("test.stdout").exists()); | 57 | assert!(temp_dir.path().join("test.stdout").exists()); |
| 58 | assert!(temp_dir.path().join("test.stderr").exists()); | 58 | assert!(temp_dir.path().join("test.stderr").exists()); |
| 59 | 59 | ||
| 60 | // Give the process a moment to complete | ||
| 61 | std::thread::sleep(Duration::from_millis(100)); | ||
| 62 | |||
| 60 | // Check that stdout contains our output | 63 | // Check that stdout contains our output |
| 61 | let stdout_content = fs::read_to_string(temp_dir.path().join("test.stdout")).unwrap(); | 64 | let stdout_content = fs::read_to_string(temp_dir.path().join("test.stdout")).unwrap(); |
| 62 | assert_eq!(stdout_content.trim(), "hello"); | 65 | assert_eq!(stdout_content.trim(), "hello"); |
