-
Notifications
You must be signed in to change notification settings - Fork 125
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
Conversation
⏳ Integration test in progress...Requested by @var-const on commit be461e5 |
@dconeybe @schmidt-sebastian Feel free to tweak/nitpick the error message and the comments. |
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.
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.")); |
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.
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.
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.
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 |
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.
The last part (false if it is not valid) does not seem to be strictly needed.
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.
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 |
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.
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.
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.
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.
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.
Yeah, I also do not know of a good way to address this.
4a7b301
@@ -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 |
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.
Yeah, I also do not know of a good way to address this.
Also improve the error message contained in the invalid futures returned from invalid objects.
Addresses b/172570071 and b/157227167.