Skip to content

Commit 5c3102e

Browse files
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.
1 parent 086d324 commit 5c3102e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

.claude/CLAUDE.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ cargo build --workspace # Debug build
5151
```
5252

5353
### Testing
54+
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+
5460
Run specific tests:
5561
```bash
5662
cargo test test_function_name # Run specific matching tests
@@ -92,13 +98,16 @@ oxen push origin main # Push to remote
9298
```
9399

94100
## Code Organization
95-
96101
- 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.
97102

98103
## 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.
102111

103112
# Making Changes
104113

0 commit comments

Comments
 (0)