Skip to content

[db] Add error kind to DbError #1687#1800

Merged
michaelvlach merged 4 commits intomainfrom
1687-db-add-error-kind-to-dberror
May 6, 2026
Merged

[db] Add error kind to DbError #1687#1800
michaelvlach merged 4 commits intomainfrom
1687-db-add-error-kind-to-dberror

Conversation

@michaelvlach
Copy link
Copy Markdown
Collaborator

No description provided.

@michaelvlach michaelvlach requested review from agnesoft and Copilot May 5, 2026 22:30
@michaelvlach michaelvlach linked an issue May 5, 2026 that may be closed by this pull request
@vercel
Copy link
Copy Markdown

vercel Bot commented May 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agdb Ready Ready Preview, Comment May 6, 2026 4:40pm

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DbErrorKind and a new DbError::new(kind, description) constructor; updated DbError comparisons to include kind.
  • Migrated query/storage/serialization code and derive macros to emit DbError with explicit kinds instead of DbError::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_error test constructs an outer error of "file not found" with a cause of "open error", which makes the source() assertion pass but inverts the usual semantics of outer.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.

Comment thread agdb/src/query/insert_nodes_query.rs
Comment thread agdb/src/query/search_query.rs Outdated
Comment thread agdb/src/query/insert_aliases_query.rs
Comment thread agdb/src/collections/vec.rs Outdated
@michaelvlach michaelvlach merged commit 96a59d0 into main May 6, 2026
15 checks passed
@michaelvlach michaelvlach deleted the 1687-db-add-error-kind-to-dberror branch May 6, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[db] Add error kind to DbError

3 participants