What is the exception contract for the .NET Google.Cloud.Firestore API?

huangapple go评论65阅读模式
英文:

What is the exception contract for the .NET Google.Cloud.Firestore API?

问题

Google的.NET Firestore库记录了其API,但没有提供关于其异常行为的任何信息。

是否有关于API可能引发的"业务线"异常的参考?例如,

  • 如果在没有有效身份验证的情况下等待FirestoreDbBuilder.BuildAsync()
  • 如果在没有网络的情况下等待FirestoreDbBuilder.BuildAsync()
  • 如果在等待CollectionReference.GetSnapshotAsync()时网络中断
  • 如果在监听CollectionReference.Listen(Action<QuerySnapshot>, CancellationToken)时网络中断

我不太担心"可执行文件格式不正确"的异常,比如如果有人删除库的DLL文件会发生什么情况。

英文:

Google's .NET Firestore library documents its API, but leaves out any information about its exception behaviour.

Is there any reference for what "line of business" exceptions can be thrown by the API? For example,

  • if I await FirestoreDbBuilder.BuildAsync() without valid authentication available
  • if I await FirestoreDbBuilder.BuildAsync() without network available
  • if the network is down when I await CollectionReference.GetSnapshotAsync()
  • if the network goes down while listening to CollectionReference.Listen(Action<QuerySnapshot>, CancellationToken)

I'm not especially concerned by "malformed executable" exceptions, like what happens if someone deletes the library DLLs.

答案1

得分: 1

抱歉,我只会翻译文本部分,不包括代码。以下是翻译好的文本:

"不好意思,我担心这没有关于这个的政策文件。

一般来说:

  • 当进行 gRPC 调用(就像 GetSnapshotAsync 一样)时,我会期望抛出一个 RpcException
  • 当调用 BuildAsync 时,这很大程度上取决于凭据:
    • 当使用默认凭据时,如果凭据以 JSON 文件的形式存在,不需要网络连接,但如果文件无效或不表示有效的凭据参数,则会抛出 InvalidOperationException 将被抛出
    • 如果直接传递凭据,只调用 BuildAsync 并不会立即使用凭据进行任何操作。

此外,如果在构建器中未指定项目 ID,则 BuildAsync 将需要自动确定 - 这将在构建实际的 FirestoreDb 时引发 ArgumentNullException。(这可能不是理想的情况;我可以看到我们可能会在以后的版本中更改为 InvalidOperationException - 但可能需要进行主要版本升级。)"

英文:

No, I'm afraid there's no policy document for this.

In general though:

  • When making gRPC calls (like GetSnapshotAsync does) I'd expect an RpcException to be thrown
  • When calling BuildAsync, it very much depends on the credentials:
    • When using default credentials, if the credentials are present in the
      form of a JSON file, no network is needed but InvalidOperationException will be thrown if the file is invalid JSON or does not represent valid credential parameters
    • If the credentials are passed directly, just calling BuildAsync doesn't do anything with the credentials immediately

Additionally, if you don't specify the project ID in the builder, BuildAsync will need to ascertain that automatically - which ends up throwing ArgumentNullException when constructing the actual FirestoreDb. (That's possibly not ideal; I can see us potentially changing that to InvalidOperationException in a later version - probably in a major version bump though.)

huangapple
  • 本文由 发表于 2023年5月22日 15:35:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76303921.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定