Skip to content
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

errors: pager API errors refactor #1160

Merged
merged 5 commits into from
Jan 23, 2025

Conversation

muzarski
Copy link
Contributor

@muzarski muzarski commented Dec 27, 2024

Ref: #519

Motivation

There are three main objectives:

Purge pager.rs module of QueryError

It's yet another module where usage of QueryError was abused. It's taken care of in this PR

Narrow return error type of [poll_]next() methods on iterators/streams

They now return a self-contained NextRow error. It's independent of QueryError.

Step forward narrowing error type of metadata related functions

Currently all top-level metadata related functions/methods (e.g. Session::refresh_metadata) return QueryError. This is because low-level methods use QueryPager API under the hood. Before this PR, the pager API would return QueryError. In the follow-up PR we will continue on purging the metadata methods of QueryError. It will be replaced with an error type designated for these operations - namely MetadataError.

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • [ ] I added relevant tests for new features and bug fixes.
  • All commits compile, pass static checks and pass test.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have provided docstrings for the public items that I want to introduce.
  • [ ] I have adjusted the documentation in ./docs/source/.
  • I added appropriate Fixes: annotations to PR description.

@muzarski muzarski marked this pull request as draft December 27, 2024 07:23
@muzarski muzarski self-assigned this Dec 27, 2024
Copy link

github-actions bot commented Dec 27, 2024

cargo semver-checks detected some API incompatibilities in this PR.
Checked commit: 04c7eec

See the following report for details:

cargo semver-checks output
./scripts/semver-checks.sh --baseline-rev 918e52267e5ce9c7dc17dbcd2ff26b4e6c15d52f
+ cargo semver-checks -p scylla -p scylla-cql --baseline-rev 918e52267e5ce9c7dc17dbcd2ff26b4e6c15d52f
     Cloning 918e52267e5ce9c7dc17dbcd2ff26b4e6c15d52f
    Building scylla v0.15.0 (current)
       Built [  27.777s] (current)
     Parsing scylla v0.15.0 (current)
      Parsed [   0.053s] (current)
    Building scylla v0.15.0 (baseline)
       Built [  24.867s] (baseline)
     Parsing scylla v0.15.0 (baseline)
      Parsed [   0.050s] (baseline)
    Checking scylla v0.15.0 -> v0.15.0 (no change)
     Checked [   0.118s] 107 checks: 104 pass, 3 fail, 0 warn, 0 skip

--- failure enum_marked_non_exhaustive: enum marked #[non_exhaustive] ---

Description:
A public enum has been marked #[non_exhaustive]. Pattern-matching on it outside of its crate must now include a wildcard pattern like `_`, or it will fail to compile.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#attr-adding-non-exhaustive
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.38.0/src/lints/enum_marked_non_exhaustive.ron

Failed in:
  enum PartitionKeyError in /home/runner/work/scylla-rust-driver/scylla-rust-driver/scylla/src/statement/prepared_statement.rs:482
  enum PartitionKeyError in /home/runner/work/scylla-rust-driver/scylla-rust-driver/scylla/src/statement/prepared_statement.rs:482

--- failure enum_variant_added: enum variant added on exhaustive enum ---

Description:
A publicly-visible enum without #[non_exhaustive] has a new variant.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#enum-variant-new
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.38.0/src/lints/enum_variant_added.ron

Failed in:
  variant LegacyNextRowError:NextRowError in /home/runner/work/scylla-rust-driver/scylla-rust-driver/scylla/src/client/pager.rs:1180

--- failure enum_variant_missing: pub enum variant removed or renamed ---

Description:
A publicly-visible enum has at least one variant that is no longer available under its prior name. It may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.38.0/src/lints/enum_variant_missing.ron

Failed in:
  variant LegacyNextRowError::QueryError, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-918e52267e5ce9c7dc17dbcd2ff26b4e6c15d52f/6aa2ec538060aafde22a82a3fb8ca7912d17f498/scylla/src/client/pager.rs:1175

     Summary semver requires new major version: 3 major and 0 minor checks failed
    Finished [  53.841s] scylla
    Building scylla-cql v0.4.0 (current)
       Built [  12.181s] (current)
     Parsing scylla-cql v0.4.0 (current)
      Parsed [   0.035s] (current)
    Building scylla-cql v0.4.0 (baseline)
       Built [  12.122s] (baseline)
     Parsing scylla-cql v0.4.0 (baseline)
      Parsed [   0.035s] (baseline)
    Checking scylla-cql v0.4.0 -> v0.4.0 (no change)
     Checked [   0.116s] 107 checks: 107 pass, 0 skip
     Summary no semver update required
    Finished [  25.234s] scylla-cql
make: *** [Makefile:61: semver-rev] Error 1

@github-actions github-actions bot added the semver-checks-breaking cargo-semver-checks reports that this PR introduces breaking API changes label Dec 27, 2024
@muzarski muzarski force-pushed the iterator-errors-refactor branch 2 times, most recently from c4b17fe to 3cfdcc7 Compare December 30, 2024 13:16
@muzarski muzarski force-pushed the iterator-errors-refactor branch from 3cfdcc7 to dc72120 Compare January 16, 2025 14:44
@muzarski muzarski marked this pull request as ready for review January 16, 2025 15:40
@muzarski muzarski requested review from wprzytula and Lorak-mmk and removed request for wprzytula January 16, 2025 15:41
@muzarski muzarski mentioned this pull request Jan 16, 2025
6 tasks
@muzarski muzarski changed the title errors: iterator API errors refactor errors: pager API errors refactor Jan 16, 2025
@muzarski muzarski added this to the 0.16.0 milestone Jan 16, 2025
@muzarski muzarski added the API-stability Part of the effort to stabilize the API label Jan 16, 2025
wprzytula
wprzytula previously approved these changes Jan 17, 2025
Comment on lines 1068 to -1065
/// Failed to deserialize result metadata associated with next page response.
#[error("Failed to deserialize result metadata associated with next page response: {0}")]
ResultMetadataParseError(#[from] ResultMetadataAndRowsCountParseError),
// TODO: This should also include a variant representing an error that occurred during
// query that fetches the next page. However, as of now, it would require that we include QueryError here.
// This would introduce a cyclic dependency: QueryError -> NextRowError -> NextPageError -> QueryError.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Commit: "iterator: narrow error type of internal items "
❓ You removed this comment, and included "RequestFailure". This does not introduce a cycle because you used "RequestError" instead of "QueryError", right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct.

Comment on lines +1884 to +1892
// FIXME 2: The specific error we expect here should appear in QueryError::NextRowError. Currently
// leaving match against both variants. This will be fixed, once `MetadataError` is further adjusted
// in a follow-up PR. The goal is to return MetadataError from all functions related to metadata fetch.
Err(QueryError::DbError(DbError::Invalid, _))
| Err(QueryError::NextRowError(NextRowError::NextPageError(
NextPageError::RequestFailure(RequestError::LastAttemptError(
RequestAttemptError::DbError(DbError::Invalid, _),
)),
))) => Ok(HashMap::new()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

❓ Why can't you just move this commit before the previous one? Then all the commits would compile and pass tests, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, I'll do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, but I lied in the PR cover letter. I mentioned that penultimate commit breaks things. I moved the commit with the fix, before iterator: narrow error type of internal items.

I marked `PartitionKeyError` as non_exhaustive. Narrowed the return type
of remaining funtions that returned `QueryError` to `PartitionKeyError`.
Added an explicit conversion function PartitionKeyError -> QueryError.
This change is required for the tests to pass after next commit. The next commit
causes the DbError in topology code to be placed under QueryError::NextRowError.

Without this change, tests fail, because we propagate the error for
Cassandra clusters, instead of ignoring it.
Narrowed the error types in multiple places in internal API of
iterator module. Now the error type we manipulate on mainly is
`NextPageError` (instead of `QueryError`).

I did not change the return type of public methods yet.
I want to do it in a separate commit.
@muzarski muzarski force-pushed the iterator-errors-refactor branch from 3047435 to 04c7eec Compare January 23, 2025 16:05
@muzarski
Copy link
Contributor Author

v1.1:

  • Rebased on main
  • Reordered commits so tests pass for all of them

@wprzytula wprzytula merged commit d40e184 into scylladb:main Jan 23, 2025
9 checks passed
@muzarski muzarski deleted the iterator-errors-refactor branch January 23, 2025 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API-stability Part of the effort to stabilize the API semver-checks-breaking cargo-semver-checks reports that this PR introduces breaking API changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants