Skip to content

Port FSTUsageValidation to C++ #2670

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 4 commits into from
Mar 28, 2019
Merged

Port FSTUsageValidation to C++ #2670

merged 4 commits into from
Mar 28, 2019

Conversation

wilhuff
Copy link
Contributor

@wilhuff wilhuff commented Mar 28, 2019

There are a few interesting things about this:

  • I named this input_validation.h to match TypeScript.
  • However, I put input_validation.h in api, the package we have for building APIs.
  • I converted Invalid Query usage exceptions to just ThrowInvalidArgument

There are two somewhat annoying consequences of this change:

  • As a C++ user on an Apple platform we'll still throw NSException
  • As a C++ user you'll see error messages in terms of the Swfit API

Making this right is really annoying because it's possible for the same library to be used both from C++ and Objective-C in a single app, so we'd have to do the right thing based on a thread_local that establishes which API surface the user is coming through. I think that's probably overkill.

We can catch the NSException in the public C++ layer if we really want to force an abort.

Copy link
Contributor

@var-const var-const left a comment

Choose a reason for hiding this comment

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

As a C++ user on an Apple platform we'll still throw NSException
As a C++ user you'll see error messages in terms of the Swfit API
Making this right is really annoying because it's possible for the same library to be used both from C++ and Objective-C in a single app, so we'd have to do the right thing based on a thread_local that establishes which API surface the user is coming through. I think that's probably overkill.

I think it would be pretty nice to have. However, we certainly don't have to support that from the get-go, so I'm fine with doing this the simple way for now and maybe we'll revisit later on.

[[noreturn]] void Throw(const char* kind, const T& error) {
#ifdef ABSL_HAVE_EXCEPTIONS
(void)kind;
throw error;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty supportive of this. Having said that, I don't think we have previously given exception safety sufficient thought to make sure client code can recover after an exception is thrown. What do you think? I don't think we have any major problems, but perhaps it would be worthwhile to do an investigation and see if anything comes up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're notably not exception safe, so if that's the bar I think we should avoid this. I've reverted this. We can revisit in the future if this becomes something customers want.

Note that abseil itself only uses this pattern in circumstances where they're implementing the standard and the standard requires an exception.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that if we expect customers to find exceptions usable, we should provide at least the basic guarantee. We're mostly relying on well-behaved RAII classes, but without designing for that explicitly, it's quite likely we have some issues. I agree with leaving this as potential future work.

* limitations under the License.
*/

#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_API_INPUT_VALIDATION_H_
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking a name like error_reporting might reflect what this file does better. However, I don't oppose the current name strongly, and I guess the fact that it matches TypeScript is a bonus.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have three classes of "error reporting":

  • runtime errors, which should be reported with util::Status
  • internal logic errors, which should be reported with HARD_ASSERT
  • user programming errors, which should be reported like this file does.

To me this means that error_reporting is ambiguous. I think it's important that this indicates that it's about only this last case. For example, internal argument checking should not ThrowInvalidArgument.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, it could be user_error_reporting or usage_error_reporting... But if you're fine with the current name, let's just leave as is.

@var-const var-const assigned wilhuff and unassigned var-const Mar 28, 2019
@mikelehen
Copy link
Contributor

I skimmed this and LGTM other than @var-const's existing feedback, so I'll just defer to his review.

@mikelehen mikelehen removed their assignment Mar 28, 2019
@wilhuff wilhuff assigned var-const and unassigned wilhuff Mar 28, 2019
@var-const var-const assigned wilhuff and unassigned var-const Mar 28, 2019
* limitations under the License.
*/

#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_API_INPUT_VALIDATION_H_
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, it could be user_error_reporting or usage_error_reporting... But if you're fine with the current name, let's just leave as is.

[[noreturn]] void Throw(const char* kind, const T& error) {
#ifdef ABSL_HAVE_EXCEPTIONS
(void)kind;
throw error;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that if we expect customers to find exceptions usable, we should provide at least the basic guarantee. We're mostly relying on well-behaved RAII classes, but without designing for that explicitly, it's quite likely we have some issues. I agree with leaving this as potential future work.

@wilhuff wilhuff removed the request for review from mikelehen March 28, 2019 20:08
@wilhuff wilhuff merged commit 2e8b918 into master Mar 28, 2019
@wilhuff wilhuff deleted the wilhuff/validation branch March 28, 2019 20:19
Corrob pushed a commit that referenced this pull request Apr 25, 2019
* Port FSTUsageValidation to C++

* Add an error log level
wilhuff added a commit to firebase/firebase-android-sdk that referenced this pull request Jul 13, 2019
wilhuff added a commit to firebase/firebase-js-sdk that referenced this pull request Jul 13, 2019
wilhuff added a commit to firebase/firebase-js-sdk that referenced this pull request Jul 16, 2019
wilhuff added a commit to firebase/firebase-android-sdk that referenced this pull request Jul 16, 2019
* Update Firestore run configuration for Android Studio 3.4.1

* Port null/NaN validation text from iOS

From firebase/firebase-ios-sdk#2670
@firebase firebase locked and limited conversation to collaborators Oct 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants