Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

[cloud_firestore][Windows] Transaction read and commit errors lose the Firestore error code (reported as `unknown`)

Đã đóng Phù hợp với người mới
#18,735 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
84/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
dart
Lĩnh vực
database, desktop-dev

Hướng nghiên cứu

Bắt đầu trong windows/cloud_firestore_plugin.cpp tại TransactionGet và trình xử lý hoàn tất giao dịch, so sánh cả hai đường dẫn với ParseError. Tái hiện trên Windows bằng các quy tắc từ chối thao tác đọc và xác minh rằng các thao tác đọc trong giao dịch và các commit thất bại báo cáo mã lỗi và thông báo của Firestore thay vì unknown. Xác nhận thay đổi bằng ví dụ giao dịch Dart được cung cấp và các kiểm tra plugin Windows liên quan.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Needs Attention platform: windows plugin: cloud_firestore reproduced type: bug
Is there an existing issue for this?
  • I have searched the existing issues.

This is the same class of defect as #18550 (firebase_database on Windows), in cloud_firestore.

Which plugins are affected?

Other (Cloud Firestore)

Which platforms are affected?

Windows

Description

On Windows, a Firestore transaction that fails reaches Dart as FirebaseException(code: 'unknown') whatever Firestore actually returned. The same failure on a plain DocumentReference.get() reports the real code (permission-denied, unavailable, …), because that path goes through ParseError.

Two paths in windows/cloud_firestore_plugin.cpp build their error without the details map that ParseError provides:

  1. TransactionGet, a read inside a transaction (L1260 at a646d55):

    result(FlutterError(error_message));
    

    That is the one-argument constructor, so the Firestore message lands in the error's code slot, with no message and no details.

  2. The transaction completion handler, when the commit fails (L1160):

    SendErrorOnPlatformThread(events_state_, "transaction_error",
                              completed_future.error_message(),
                              flutter::EncodableValue());
    

_flutterfire_internals' platformExceptionToFirebaseException reads the code only from details['code'] and falls back to unknown. It reads the message from details['message'], or else PlatformException.message. So:

  • a failed transaction read becomes [cloud_firestore/unknown] with an empty message, because the real message went into PlatformException.code, which is discarded;
  • a failed commit becomes [cloud_firestore/unknown], keeping the message but not the code.

Apps can't tell a rules or App Check refusal (permission-denied) from contention (aborted) or a transient network failure. Anything that retries or reports on the code misclassifies it: we retried a permanent permission-denied as if it were transient.

Observed: the read path in production, from a Windows desktop app. The stack ran through FirebaseFirestoreHostApi.transactionGet → MethodChannelTransaction.get and ended in FirebaseException: [cloud_firestore/unknown] with no message. Earlier in the same session, the same account's plain get() of another document failed with [cloud_firestore/permission-denied]. The commit path is from reading the code; it has the same shape.

Suggested fix (not yet compiled on Windows), giving both paths the shape ParseError already uses:

@@ TransactionStreamHandler completion
           } else {
+            EncodableMap details;
+            details[EncodableValue("code")] =
+                EncodableValue(CloudFirestorePlugin::GetErrorCode(
+                    static_cast<firebase::firestore::Error>(
+                        completed_future.error())));
+            details[EncodableValue("message")] =
+                EncodableValue(completed_future.error_message());
             SendErrorOnPlatformThread(events_state_, "transaction_error",
                                       completed_future.error_message(),
-                                      flutter::EncodableValue());
+                                      EncodableValue(details));
           }
@@ void CloudFirestorePlugin::TransactionGet(
   if (error_code != Error::kErrorOk) {
-    result(FlutterError(error_message));
+    EncodableMap details;
+    details[EncodableValue("code")] = EncodableValue(GetErrorCode(error_code));
+    details[EncodableValue("message")] = EncodableValue(error_message);
+    result(FlutterError("firebase_firestore", error_message, details));
   } else {
Reproducing the issue

On Windows, with rules that deny reading a document:

match /denied/{doc} { allow read: if false; }
try {
  await FirebaseFirestore.instance.runTransaction((tx) async {
    await tx.get(FirebaseFirestore.instance.doc('denied/doc'));
  });
} on FirebaseException catch (e) {
  print('${e.code}: ${e.message}');
}
  • Expected: permission-denied: Missing or insufficient permissions., as the same read outside a transaction reports.
  • Actual: unknown: (empty message).

A transaction whose write is denied by rules shows the commit path: the code is unknown and the message is kept.

Firebase Core version

4.13.0 (cloud_firestore 6.8.0; the code is unchanged in 6.9.0 and on main at a646d55)

Flutter Version

3.47.4 (Dart 3.13.3)

Relevant Log Output
FirebaseException: [cloud_firestore/unknown]
_extractReplyValueOrThrow (messages.pigeon.dart:27)
FirebaseFirestoreHostApi.transactionGet (messages.pigeon.dart:1477)
MethodChannelTransaction.get (method_channel_transaction.dart:50)
Transaction.get (transaction.dart:28)
Flutter dependencies

cloud_firestore 6.8.0, cloud_firestore_platform_interface 8.0.6, _flutterfire_internals 1.3.76, firebase_core 4.13.0. Windows 11 (build 26200), release build.

Additional context and comments

Every other error path in the file builds details itself (ParseError, the bundle loader), so this looks like two call sites that were missed rather than a design choice.

Ngôn ngữ chính
Dart
Star
9.3k
Fork
4.1k
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
82

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của firebase/flutterfire

Tất cả issue của firebase/flutterfire

Issue tương tự

Thêm issue về Dart

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.