vors / ZLocation

ZLocation is the new Jump-Location
MIT License
568 stars 29 forks source link

Unable to cast object of type 'LiteDB.ObjectId' to type 'System.String' #68

Open weloytty opened 6 years ago

weloytty commented 6 years ago

after a day or so of using ZLocation, I start to get this error:

C:\Users\whatever\AppData\Roaming\Local\tempz auto                                                                    
Exception calling "ToObject" with "2" argument(s): "Unable to cast object of type 'LiteDB.ObjectId' to type 'System.String'."     
At C:\Program Files\PowerShell\Modules\ZLocation\1.0.0\ZLocation.LiteDB.psm1:15 char:5                                            
+     ,$mapper.ToObject($type, $obj)                                                                                              
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                              
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException                                                         
+ FullyQualifiedErrorId : InvalidCastException     

When I go and look at z-location.db, I see, along with the normal entries, an entry like this:

[ { "_id": {"$oid": "5ba9f338cfbf5e28a8f1314c"}, "weight": 1.0 } ]

If I remove that from the db, things work again. (Until a day or so later when I get the error again)

vors commented 6 years ago

@cspotcode do you know where that may come from?

cspotcode commented 6 years ago

@vors, no I'm not sure, except it seems like somewhere we're accidentally putting a nonsense entry into the database. Maybe we're passing an incomplete object to the $mapper somewhere? Like, what happens if we accidentally try to increase the weight for a path when no such path entry exists in the database? Just a guess.

cspotcode commented 6 years ago

Now that I think about it for a few more minutes, I suspect that's the problem. I suspect that somewhere we're calling Add-ZWeight or $service.add() with a null $path. We have the Location class's path field mapped as LiteDB's _id. (LiteDB makes _id mandatory; otherwise I would have named it path within the database) So if $path/_id is unspecified, the database will auto-create an ID for that row, except the auto-created IDs aren't strings. Later, we try to map that row to a [Location] instance, and it fails because it can't convert the _id to Location's path field.