firebase - Flutter firebase - 无法捕获异常抛出的白色尝试使用带有空键的 map 更新文档

标签 firebase flutter try-catch

在尝试使用带有空键的 map 更新 Firestore 中的文档时(我的代码中的错误),我无法捕获异常,这导致了应用程序崩溃。

这是一个示例代码:

try {
Map<String, dynamic> crash = {"": 3}; // this is an empty key (bug)
await docRef.collection('collection').document('doc').updateData({"ABC": crash});
} catch (err) {
print(err);
}

异常(相当合理):

*** Assertion failure in auto firebase::firestore::model::FieldPath::FromServerFormat(const absl::string_view)::(anonymous class)::operator()() const(), /project/ios/Pods/FirebaseFirestore/Firestore/core/src/firebase/firestore/model/field_path.cc:90
Lost connection to device.
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'FIRESTORE INTERNAL ASSERTION FAILED: Invalid field path (s3SEDn5nhnWiqeZjpDmY.``). Paths must not be empty, begin with '.', end with '.', or contain '..' (expected !segment.empty())'

我没有看到错误打印到控制台,也没有看到那里设置的断点。

我的问题/问题:

  1. 我是否以错误的方式使用了 try catch block ?为什么 catch 语句不起作用?

  2. 应用崩溃后,尝试重新启动失败,并出现以下错误:

FileSystemException: Getting current working directory failed, path = '' (OS Error: Too many open files in system, errno = 23)

只有卸载并重新安装该应用程序才有效。 知道这是否正常吗?如果没有,我该怎么办?

在 iOS 和 Android 上都崩溃, Firestore 插件版本 cloud_firestore: ^0.12.7

最佳答案

我在尝试使用没有互联网连接(模拟器)的 map 捕获 updateData 上的异常时遇到了类似的问题。

    await Firestore.instance.collection('collection').document(doc).updateDataa({"ABC": crash}).timeout(Duration(seconds: 10));

这是我处理超时并返回连接错误的唯一方法!

关于firebase - Flutter firebase - 无法捕获异常抛出的白色尝试使用带有空键的 map 更新文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56942281/

相关文章:

javascript - 为什么我的快照返回 null,即使 Firebase 数据库上有值

flutter - 如何从这种类型的列表访问单个值?

flutter - Flutter 如何让底部导航栏覆盖主页面?

python - Python尝试除错误外,程序崩溃

iOS Firebase Swift,在 OnDisconnect 上使用以监控在线状态不起作用

java - 如何在 Firebase 评级系统中仅允许每个用户评级一次

c# - 无法在 C# 中捕获 0xC0000005 异常

c++ - 为什么 SymGetSymFromAddr64 不工作?它返回错误代码 126

android - Firebase 远程配置总是命中服务器

flutter - 启用时切换