-
Notifications
You must be signed in to change notification settings - Fork 25
CLAUDE.md: error handling + test instructions updates #412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,12 @@ cargo build --workspace # Debug build | |
| ``` | ||
|
|
||
| ### Testing | ||
| Many tests require the oxen server to be running. If it is not running on port 3000 and | ||
| a test fails because it cannot connect to oxen-server, then start it: | ||
| ```bash | ||
| cargo run -p oxen-server start | ||
| ``` | ||
|
|
||
| Run specific tests: | ||
| ```bash | ||
| cargo test test_function_name # Run specific matching tests | ||
|
|
@@ -92,13 +98,16 @@ oxen push origin main # Push to remote | |
| ``` | ||
|
|
||
| ## Code Organization | ||
|
|
||
| - 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. | ||
|
|
||
| ## Error Handling | ||
| - Use `OxenError` for all error types | ||
| - Functions should return `Result<T, OxenError>` | ||
| - Implement proper error propagation through the `?` operator | ||
| - Use the result type (`Result<T, Error>`) when an operation could fail. | ||
| - Never use `.unwrap()` or `.expect()` on a `Result` or on an `Option`. | ||
| + 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. | ||
| - 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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix typo in error type guidance. "similiar" is misspelled. ✏️ Proposed fix-- 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.
+- 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 similar errors.🤖 Prompt for AI Agents |
||
| - 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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix typos in OxenError variant guidance. Two issues on this line:
✏️ Proposed fixes-- 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.
+- Make sure there's an `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.-- 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.
+- Make sure there's an `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.Actually, there's also "similiar" that needs fixing: -- 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.
+- 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 similar errors.Combined fix: -- 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.
+- Make sure there's an `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.🤖 Prompt for AI Agents |
||
| - `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>` | ||
| - Implement proper error propagation through the `?` operator. | ||
|
|
||
| # Making Changes | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix typo in test exception note.
The word "descrptive" is misspelled.
✏️ Proposed fix
🤖 Prompt for AI Agents