You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CLAUDE.md: error handling + test instructions updates
Updated the `CLAUDE.md` file to expound on error handling conventions.
`OxenError` is top-level unifying type. Encourage to use specific errors and
wrap in `OxenError` variants with `#[from]` conversions.
Included instruction to ensure the `oxen-server` server is running for tests.
Many tests require the oxen server to be running. If it is not running on port 3000 and
55
+
a test fails because it cannot connect to oxen-server, then start it:
56
+
```bash
57
+
cargo run -p oxen-server start
58
+
```
59
+
54
60
Run specific tests:
55
61
```bash
56
62
cargo test test_function_name # Run specific matching tests
@@ -92,13 +98,16 @@ oxen push origin main # Push to remote
92
98
```
93
99
94
100
## Code Organization
95
-
96
101
- We define module exports in a `<module_name>.rs` file at the same level as the corresponding `module_name/` directory and *NOT* the older `mod.rs` pattern.
97
102
98
103
## Error Handling
99
-
- Use `OxenError` for all error types
100
-
- Functions should return `Result<T, OxenError>`
101
-
- Implement proper error propagation through the `?` operator
104
+
- Use the result type (`Result<T, Error>`) when an operation could fail.
105
+
- Never use `.unwrap()` or `.expect()` on a `Result` or on an `Option`.
106
+
+ Exception: In test-only code, it is ok to use use `.expect(<descrptive explanation of invariant that was violated>)` since we want to fail fast and have good stack traces for failing test cases.
107
+
- Use as specific of an error type as possible for a function. Don't use a wider type unless it's necessary. When making modules and related pieces of code, try to use a locally-defined error enum for them if they all have similiar errors.
108
+
- Make sure there's a `OxenError` variant for every error type. Be liberal in wrapping other modules error types, or other specific error types, in a new variant. Use a `Box<>` wrapper for it and have a `#[from]` to derive.
109
+
-`OxenError` is the top-level type for everything. If you need to unify different error types into one, use `OxenError`. These kinds of functions should return `Result<T, OxenError>`
110
+
- Implement proper error propagation through the `?` operator.
0 commit comments