Skip to content

Commit 12b93b5

Browse files
committed
Improve error handling and project infrastructure
This commit addresses critical issues identified in the code review: ## Error Handling Improvements - Replace unwrap() calls with proper error handling in watch.rs - Make watch() and watch_directory() return Result<()> - Use anyhow::Context for better error messages - Handle terminal raw mode failures gracefully - Add descriptive error context throughout the codebase ## Code Quality - Define FILE_SETTLE_DURATION constant (150ms) - Improve error messages for better debugging - Ensure proper cleanup on errors via defer! macro ## CI/CD Enhancements - Add macOS to cross-platform test matrix - Update deprecated actions-rs/toolchain to dtolnay/rust-toolchain - Ensure all three major platforms are tested ## Documentation - Add CONTRIBUTING.md with comprehensive guidelines - Add CHANGELOG.md following Keep a Changelog format - Document contribution process and code standards - Add machine database contribution instructions ## Bug Fixes - Fix potential panics in terminal mode operations - Improve event polling error handling - Better handling of keyboard and file system events These changes improve code robustness and make the codebase more production-ready while establishing better processes for contributors.
1 parent ab092ea commit 12b93b5

File tree

6 files changed

+307
-42
lines changed

6 files changed

+307
-42
lines changed

.github/workflows/crossplatform-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
os: [ubuntu-latest, windows-latest]
14+
os: [ubuntu-latest, windows-latest, macos-latest]
1515

1616
steps:
1717
- uses: actions/checkout@v4

.github/workflows/release.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ jobs:
3434
sudo apt-get update
3535
sudo apt-get install -y libudev-dev libusb-1.0-0-dev pkg-config
3636
37-
- uses: actions-rs/toolchain@v1
37+
- uses: dtolnay/rust-toolchain@stable
3838
with:
39-
toolchain: stable
40-
target: ${{ matrix.target }}
41-
override: true
39+
targets: ${{ matrix.target }}
4240

4341
- name: Build
4442
run: cargo build --release --target ${{ matrix.target }}

CHANGELOG.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Changed
11+
- Improved error handling in watch service - replaced unwraps with proper Result propagation
12+
- watch() and watch_directory() functions now return Result<()> for better error handling
13+
- Enhanced CI/CD: Added macOS to cross-platform test matrix
14+
- Updated GitHub Actions: Migrated from deprecated actions-rs/toolchain to dtolnay/rust-toolchain
15+
16+
### Added
17+
- FILE_SETTLE_DURATION constant for file modification debounce delay
18+
- CONTRIBUTING.md with comprehensive contribution guidelines
19+
- CHANGELOG.md to track version history
20+
- Better error context messages throughout the codebase
21+
22+
### Fixed
23+
- Removed panic-prone unwrap() calls in terminal raw mode operations
24+
- Improved graceful error handling for keyboard and file system events
25+
- Fixed potential crashes in watch loop when terminal mode fails
26+
27+
## [0.1.3] - 2024-XX-XX
28+
29+
### Changed
30+
- Switched documentation from Jekyll to MkDocs
31+
- Updated README with improved structure
32+
33+
### Fixed
34+
- Various bug fixes and improvements
35+
36+
## [0.1.2] - 2024-XX-XX
37+
38+
### Added
39+
- Cross-platform support improvements
40+
41+
## [0.1.1] - 2024-XX-XX
42+
43+
### Fixed
44+
- Installation script improvements
45+
46+
## [0.1.0] - 2024-XX-XX
47+
48+
### Added
49+
- Initial release
50+
- File watching and conversion functionality
51+
- USB drive detection for Linux, macOS, and Windows
52+
- Machine database with format support
53+
- Inkscape integration for file conversion
54+
- Configuration management with TOML
55+
- Interactive machine selection with fuzzy matching
56+
- Command-line interface with multiple commands
57+
- Self-update functionality
58+
- Cross-platform installation scripts
59+
60+
[Unreleased]: https://github.com/osteele/stitch-sync/compare/v0.1.3...HEAD
61+
[0.1.3]: https://github.com/osteele/stitch-sync/compare/v0.1.2...v0.1.3
62+
[0.1.2]: https://github.com/osteele/stitch-sync/compare/v0.1.1...v0.1.2
63+
[0.1.1]: https://github.com/osteele/stitch-sync/compare/v0.1.0...v0.1.1
64+
[0.1.0]: https://github.com/osteele/stitch-sync/releases/tag/v0.1.0

CONTRIBUTING.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# Contributing to Stitch-sync
2+
3+
Thank you for your interest in contributing to Stitch-sync! This document provides guidelines and instructions for contributing to the project.
4+
5+
## Code of Conduct
6+
7+
This project adheres to a code of conduct that we expect all contributors to follow. Please be respectful and constructive in all interactions.
8+
9+
## How to Contribute
10+
11+
### Reporting Bugs
12+
13+
If you find a bug, please create an issue on GitHub with:
14+
- A clear, descriptive title
15+
- Detailed steps to reproduce the issue
16+
- Expected behavior vs. actual behavior
17+
- Your environment (OS, Rust version, Inkscape version)
18+
- Any relevant error messages or logs
19+
20+
### Suggesting Features
21+
22+
Feature suggestions are welcome! Please create an issue with:
23+
- A clear description of the feature
24+
- The use case and why it would be valuable
25+
- Any relevant examples from similar tools
26+
27+
### Contributing Code
28+
29+
1. **Fork the repository** and create a new branch from `main`
30+
```bash
31+
git checkout -b feature/your-feature-name
32+
```
33+
34+
2. **Set up your development environment**
35+
```bash
36+
# Install Rust (if not already installed)
37+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
38+
39+
# Clone your fork
40+
git clone https://github.com/YOUR_USERNAME/stitch-sync
41+
cd stitch-sync
42+
43+
# Install dependencies (Linux only)
44+
sudo apt-get install libudev-dev # Ubuntu/Debian
45+
46+
# Build the project
47+
cargo build
48+
49+
# Run tests
50+
cargo test
51+
```
52+
53+
3. **Make your changes**
54+
- Write clean, readable code that follows Rust conventions
55+
- Add tests for new functionality
56+
- Update documentation as needed
57+
- Ensure all tests pass: `cargo test`
58+
- Run the formatter: `cargo fmt`
59+
- Run the linter: `cargo clippy`
60+
61+
4. **Commit your changes**
62+
- Use clear, descriptive commit messages
63+
- Follow conventional commits format when possible:
64+
- `feat:` for new features
65+
- `fix:` for bug fixes
66+
- `docs:` for documentation changes
67+
- `test:` for test additions/changes
68+
- `refactor:` for code refactoring
69+
- `chore:` for maintenance tasks
70+
71+
5. **Push to your fork and submit a pull request**
72+
```bash
73+
git push origin feature/your-feature-name
74+
```
75+
76+
6. **Wait for review**
77+
- Address any feedback from reviewers
78+
- Keep your branch up to date with main
79+
80+
## Development Guidelines
81+
82+
### Code Style
83+
84+
- Follow standard Rust formatting (`cargo fmt`)
85+
- Use meaningful variable and function names
86+
- Add comments for complex logic
87+
- Keep functions focused and reasonably sized
88+
89+
### Error Handling
90+
91+
- Use `anyhow::Result` for error propagation
92+
- Add context to errors using `.context()`
93+
- Avoid `unwrap()` in production code
94+
- Use `expect()` with descriptive messages only for truly unreachable cases
95+
96+
### Testing
97+
98+
- Write unit tests for new functions
99+
- Add integration tests for end-to-end functionality
100+
- Test on multiple platforms when possible
101+
- Mock external dependencies when appropriate
102+
103+
### Documentation
104+
105+
- Add doc comments (`///`) for public functions and types
106+
- Update README.md for user-facing changes
107+
- Update docs/ for significant features
108+
- Include examples in documentation
109+
110+
## Contributing to the Machine Database
111+
112+
The machine database (`src/types/machines.csv`) can always be expanded. To add a machine:
113+
114+
1. Add a row to `machines.csv` with:
115+
- Machine Name
116+
- Supported File Formats (comma-separated)
117+
- USB Path (if specific path required)
118+
- Notes (optional)
119+
- Design Size (optional)
120+
- Synonyms (optional, comma-separated)
121+
122+
2. Verify the information against manufacturer specifications
123+
124+
3. Test with the actual machine if possible
125+
126+
4. Submit a pull request with the addition
127+
128+
## Project Structure
129+
130+
```
131+
stitch-sync/
132+
├── src/
133+
│ ├── cli/ # Command-line interface
134+
│ ├── config/ # Configuration management
135+
│ ├── services/ # Core business logic
136+
│ ├── types/ # Domain models
137+
│ └── utils/ # Helper functions
138+
├── docs/ # Documentation
139+
├── scripts/ # Installation and utility scripts
140+
└── .github/workflows/ # CI/CD configuration
141+
```
142+
143+
## Building for Different Platforms
144+
145+
### Linux
146+
```bash
147+
cargo build --release
148+
```
149+
150+
### macOS
151+
```bash
152+
cargo build --release
153+
```
154+
155+
### Windows
156+
```bash
157+
cargo build --release
158+
```
159+
160+
Cross-compilation is also supported. See the release workflow for examples.
161+
162+
## Running Tests
163+
164+
```bash
165+
# Run all tests
166+
cargo test
167+
168+
# Run tests with output
169+
cargo test -- --nocapture
170+
171+
# Run specific test
172+
cargo test test_name
173+
174+
# Run tests for specific module
175+
cargo test services::
176+
```
177+
178+
## Getting Help
179+
180+
- Check existing issues and pull requests
181+
- Read the [developer documentation](docs/developer-notes.md)
182+
- Create a discussion on GitHub for questions
183+
184+
## License
185+
186+
By contributing to Stitch-sync, you agree that your contributions will be licensed under the MIT License.
187+
188+
Thank you for contributing!

src/cli/commands.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,7 @@ fn watch_command<W: Write>(
358358
.collect::<Vec<_>>(),
359359
&preferred_format,
360360
inkscape,
361-
);
362-
Ok(())
361+
)
363362
}
364363

365364
fn update_command<W: Write>(dry_run: bool, writer: &mut W) -> Result<()> {

0 commit comments

Comments
 (0)