Skip to content

Add is_valid methods to the public API classes that can be in an invalid state #560

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

Merged
merged 7 commits into from
Jul 23, 2021

Conversation

var-const
Copy link
Contributor

@var-const var-const commented Jul 21, 2021

Also improve the error message contained in the invalid futures returned from invalid objects.

Addresses b/172570071 and b/157227167.

@google-cla google-cla bot added the cla: yes label Jul 21, 2021
@var-const var-const added api: firestore tests-requested: quick Trigger a quick set of integration tests. labels Jul 21, 2021
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. and removed tests-requested: quick Trigger a quick set of integration tests. labels Jul 21, 2021
@github-actions
Copy link

github-actions bot commented Jul 21, 2021

⏳  Integration test in progress...

Requested by @var-const on commit be461e5
Last updated: Thu Jul 22 21:33 PDT 2021
View integration test log & download artifacts

@var-const
Copy link
Contributor Author

@dconeybe @schmidt-sebastian Feel free to tweak/nitpick the error message and the comments.

@github-actions github-actions bot added the tests: succeeded This PR's integration tests succeeded. label Jul 21, 2021
@firebase-workflow-trigger firebase-workflow-trigger bot removed the tests: in-progress This PR's integration tests are in progress. label Jul 21, 2021
dconeybe
dconeybe previously approved these changes Jul 21, 2021
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

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

LGTM with nits you can ignore.

"The object that issued this future is in an invalid state. This can be "
"because:\n- the object was default-constructed and never reassigned;\n"
"- the object was moved from;\n- the Firestore instance with which the "
"object was associated has been destroyed."));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it common to have error messages like this in C++? I know that in Java a line break in an error message would be pretty annoying and make the overall message (which includes the stacktrace) less readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, removed the newlines.

@@ -159,6 +159,19 @@ class DocumentChange {
*/
virtual std::size_t new_index() const;

/**
* @brief Returns true if this `DocumentChange` is valid, false if it is
Copy link
Contributor

Choose a reason for hiding this comment

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

The last part (false if it is not valid) does not seem to be strictly needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, but historically the approach was to be as clear as possible, at the cost of some redundancy. I'd rather keep as is.

@@ -637,6 +637,18 @@ class Query {
std::function<void(const QuerySnapshot&, Error, const std::string&)>
callback);

/**
* @brief Returns true if this `Query` is valid, false if it is not valid. An
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if we need to mention this, but the main usage for this API will likely be via CollectionReference.is_valid. I am not sure if all of our users are aware of our type hierarchy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about this too. Unfortunately, I don't see a great way around this. We could make this function virtual just to override it to do the same thing in the derived class, but it gives the impression that the behavior of this function is somehow different in the derived class, which can be confusing. We could define the function with the same name without making it virtual, but that would be shadowing the function in the main class and is likely to trigger compilation warnings and just in general looks questionable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I also do not know of a good way to address this.

@schmidt-sebastian schmidt-sebastian removed their assignment Jul 21, 2021
@var-const var-const added tests-requested: quick Trigger a quick set of integration tests. and removed tests: succeeded This PR's integration tests succeeded. labels Jul 22, 2021
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. and removed tests-requested: quick Trigger a quick set of integration tests. labels Jul 22, 2021
@var-const var-const enabled auto-merge July 22, 2021 00:09
@dconeybe dconeybe assigned var-const and unassigned dconeybe Jul 22, 2021
@github-actions github-actions bot added the tests: failed This PR's integration tests failed. label Jul 22, 2021
@firebase-workflow-trigger firebase-workflow-trigger bot removed the tests: in-progress This PR's integration tests are in progress. label Jul 22, 2021
@@ -637,6 +637,18 @@ class Query {
std::function<void(const QuerySnapshot&, Error, const std::string&)>
callback);

/**
* @brief Returns true if this `Query` is valid, false if it is not valid. An
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I also do not know of a good way to address this.

@schmidt-sebastian schmidt-sebastian removed their assignment Jul 22, 2021
@var-const var-const added tests-requested: quick Trigger a quick set of integration tests. and removed tests: failed This PR's integration tests failed. labels Jul 22, 2021
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. and removed tests-requested: quick Trigger a quick set of integration tests. labels Jul 22, 2021
@var-const var-const added tests-requested: quick Trigger a quick set of integration tests. and removed tests: in-progress This PR's integration tests are in progress. labels Jul 23, 2021
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. tests: succeeded This PR's integration tests succeeded. and removed tests-requested: quick Trigger a quick set of integration tests. labels Jul 23, 2021
@firebase-workflow-trigger firebase-workflow-trigger bot removed the tests: in-progress This PR's integration tests are in progress. label Jul 23, 2021
@var-const var-const merged commit be461e5 into main Jul 23, 2021
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. and removed tests: succeeded This PR's integration tests succeeded. labels Jul 23, 2021
@firebase firebase locked and limited conversation to collaborators Aug 23, 2021
@jonsimantov jonsimantov deleted the varconst/error-message-on-invalid branch December 22, 2021 22:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: firestore cla: yes tests: in-progress This PR's integration tests are in progress.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants