[db] Add error kind to DbError #1687#1800
Merged
michaelvlach merged 4 commits intomainfrom May 6, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces typed error categorization to the Rust agdb crate by adding DbErrorKind to DbError, migrating the codebase and tests away from string-based error construction, and updating several error messages to be more specific/consistent.
Changes:
- Added
DbErrorKindand a newDbError::new(kind, description)constructor; updatedDbErrorcomparisons to includekind. - Migrated query/storage/serialization code and derive macros to emit
DbErrorwith explicit kinds instead ofDbError::from(...)/"msg".into(). - Updated many tests (and a schema migration example) to assert on the new error shapes/messages.
Reviewed changes
Copilot reviewed 37 out of 37 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/schema_migration/src/main.rs | Update example to construct DbError with an explicit DbErrorKind. |
| agdb/tests/select_values_test.rs | Adjust expected error message for missing key in select-values query. |
| agdb/tests/remove_nodes_test.rs | Update rollback tests to assert DbError::new(kind, ...) values. |
| agdb/tests/remove_index_test.rs | Update rollback tests to assert DbError::new(kind, ...) values. |
| agdb/tests/remove_edges_test.rs | Update rollback tests to assert DbError::new(kind, ...) values. |
| agdb/tests/remove_aliases_test.rs | Update rollback tests to assert DbError::new(kind, ...) values. |
| agdb/tests/insert_values_test.rs | Update rollback tests and expected messages for length mismatch errors. |
| agdb/tests/insert_nodes_test.rs | Update rollback tests and expected messages for length mismatch errors. |
| agdb/tests/insert_index_test.rs | Update rollback tests and index-exists error to typed DbError. |
| agdb/tests/insert_edges_test.rs | Update rollback tests and expected messages for values/count mismatch errors. |
| agdb/tests/insert_aliases_test.rs | Update rollback tests and expected message for ids/aliases mismatch. |
| agdb/tests/efficient_agdb/mod.rs | Update example-like tests to use typed DbError kinds. |
| agdb/tests/derive_feature_test/mod.rs | Update expected type-conversion error message text. |
| agdb/tests/db_test.rs | Update Db::new failure assertions (top-level + cause message). |
| agdb/src/utilities/serialize.rs | Use typed DbErrorKind across deserialize bounds/type failures; update unit tests accordingly. |
| agdb/src/storage/storage_records.rs | Return DbError::new(DbErrorKind::NotFound, ...) for missing record index. |
| agdb/src/storage/memory_storage.rs | Update storage tests to assert typed DbError kinds/messages. |
| agdb/src/storage/file_storage.rs | Update storage tests to assert typed DbError kinds/messages. |
| agdb/src/storage/file_storage_memory_mapped.rs | Update storage tests to assert typed DbError kinds/messages. |
| agdb/src/storage.rs | Use typed DbErrorKind for transaction/version/size validation errors. |
| agdb/src/query/select_values_query.rs | Return typed NotFound error when a requested key is missing. |
| agdb/src/query/search_query.rs | Use typed DbErrorKind for malformed/unsupported index search conditions. |
| agdb/src/query/insert_values_query.rs | Return typed error for ids/values length mismatches. |
| agdb/src/query/insert_nodes_query.rs | Return typed errors for aliases/values and ids/values validation failures. |
| agdb/src/query/insert_edges_query.rs | Return typed errors for invalid ids and values/count mismatch. |
| agdb/src/query/insert_aliases_query.rs | Return typed errors for invalid input and unsupported search usage. |
| agdb/src/lib.rs | Re-export DbErrorKind from the crate root. |
| agdb/src/graph.rs | Use typed InvalidIndex errors for graph index validation. |
| agdb/src/db/db_value.rs | Use typed TypeError/OutOfBounds errors for conversions; update tests accordingly. |
| agdb/src/db/db_value_index.rs | Improve deserialize error detail and add DbErrorKind categorization. |
| agdb/src/db/db_error.rs | Introduce DbErrorKind, add kind to DbError, new constructor, update conversions + tests. |
| agdb/src/db.rs | Use typed errors for db creation and various not-found/integrity paths. |
| agdb/src/collections/vec.rs | Remove From<String> requirement on error type and emit typed errors for index validation. |
| agdb/src/collections/map.rs | Use typed errors for (de)serialization validation failures; update tests accordingly. |
| agdb_server/src/db_pool/user_db.rs | Use typed NotAllowed error for disallowed mutable queries. |
| agdb_derive/src/db_type.rs | Update generated conversions to return typed DbError kinds. |
| agdb_derive/src/db_serialize.rs | Update generated enum deserialization to return typed TypeError on invalid variants. |
Comments suppressed due to low confidence (1)
agdb/src/db/db_error.rs:221
- The
derived_from_errortest constructs an outer error of "file not found" with a cause of "open error", which makes thesource()assertion pass but inverts the usual semantics ofouter.caused_by(inner). Consider swapping these so the outer error is "open error" and the source/cause is "file not found" to keep the test aligned with typical error chaining.
#[test]
fn derived_from_error() {
let file = file!();
let col__ = column!();
let line = line!();
let error = DbError::new(DbErrorKind::NotEnoughData, "open error");
let new_error = DbError::new(DbErrorKind::NotEnoughData, "file not found").caused_by(error);
assert_eq!(
new_error.source().unwrap().to_string(),
format!(
"open error (at {}:{}:{})",
file.replace('\\', "/"),
line + 1,
col__
)
);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
agnesoft
approved these changes
May 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.