Reputation: 806
I am trying to write a document to the collection, and it was working till 12 hours ago.
The data I am trying to write:
var uploadData = {
'date_of_birth': _dateOfBirth,
'name': _name,
'hip_size': _hipSize,
'height': _height,
'tennis_level': _tennisLevel,
'days_available': _daysOfWeek,
'weight': _weight,
'image': imageUrl,
'secondary_courts': [],
'travel_range': _travelRange.km,
'travel_range_name': _travelRange.rangeName,
'play_hand': playHand,
};
await firestore.collection('users').doc(user.user.uid).set(uploadData);
The error:
W/Firestore( 8153): (23.0.1) [WriteStream]: (43c3cb2) Stream closed with status: Status{code=INVALID_ARGUMENT, description=Error compiling rules:
W/Firestore( 8153): L25:1 Unexpected '<EOF>'.
W/Firestore( 8153): L25:1 missing '}' at '<EOF>', cause=null}.
[cloud_firestore/invalid-argument] Client specified an invalid argument. Note that this differs from failed-precondition. invalid-argument indicates arguments that are problematic regardless of the state of the system (e.g., an invalid field name).
I have retyped the data again. I ran a regexp for in 2 editors. I can't seem to make heads or tails of it.
The data types:
//Profile and login Data
String _email;
String _password;
DateTime _dateOfBirth;
Map<String, String> _name = {
'first_name': '',
'middle_name': '',
'last_name': '',
'full_name': '',
};
double _hipSize;
double _weight;
Map<String, int> _height = {
'feet': 0,
'inches': 0,
};
double _tennisLevel;
Map<String, bool> _daysOfWeek = {
'sunday': false,
'monday': false,
'tuesday': false,
'wednesday': false,
'thursday': false,
'friday': false,
'saturday': false,
};
List<TennisCourt> _tennisCourts = [];
File _profileImage;
String _daysAvailable = '';
TravelRange _travelRange;
bool isRightHanded = true;
String playHand = isRightHanded ? 'right' : 'left';
I have also logged the runTimeTypes of all the data:
date_of_birth: DateTime
name: _InternalLinkedHashMap<String, String>
hip_size: double
height: _InternalLinkedHashMap<String, int>
tennis_level: double
days_available: _InternalLinkedHashMap<String, bool>
weight: double
image: String
secondary_courts: List<dynamic>
travel_range: double
travel_range_name: String
play_hand: String
Upvotes: 1
Views: 3500
Reputation: 337
As already established, the error message could mean a lot of things but what worked for me was simply reducing the amount of data I was uploading to Firestore at once.
For instance, instead of uploading 1,000 data at once, when I uploaded them in batches, say 300 each, the error message disappeared.
I hope this helps someone and I really hope Firestore starts giving us the exact errors. This will save us hours of debugging.
Upvotes: 1
Reputation: 1533
I tested my code enough to state that, in my case, the problem was that my transaction exceeded the maximum number of operations allowed. The current limit for the number of operations within a single Firestore transaction is 500. It was throwing this error when exceeding the limit, although unfortunately, its message doesn't indicate anything about it...
Upvotes: 1
Reputation: 7945
This is a very unspecific Firebase error and could have many different reasons. In my case, my Object was too deeply nested. Firebase only allows nesting objects only up to a certain levels. I solved it by encoding the object to a String when writing and seconding it when reading.
I wish Firebase would do a better job at providing error codes as this took quite a while for me to figure out.
Upvotes: 1
Reputation: 724
In my case, I was filtering the same field twice, so I removed it and it was solved.
Upvotes: 2
Reputation: 806
This issue was caused by an error in the firestore.rules
file. A syntax error to exact.
Upvotes: 3
Reputation: 12383
All the data you are sending has to be one of the accepted data in Firebase, i.e: String, number, List, Map, boolean ..etc
Make sure that the data you are sending are not objects you defined. From your post, I am suspicious of these: playHand
and _daysOfWeek
.
Try to remove them and test if it works, or in your model, create a toMap()
method.
null
.Upvotes: 1