Getting Sync fn TypeError when saving a document in the gateway


When I try to create a new document in the gateway bucket as an ADMIN user, it seems that the sync function does not like ints. It throws this exception for each field where an int is stored as you can see in the following log:

2016-05-23T10:55:44.898Z WARNING: Sync fn exception: TypeError; doc = map[end:%!s(float64=1.464014954e+12) destination:EugenieLand _id:EventData@@8eb4b76c-f2e9-4525-8119-1114b0e01154 eventType:ADMIN_EVENT docType:EventData creationDate:%!s(float64=1.464000944e+09) title:INFO: Hello all start:%!s(float64=1.464011354e+12) location:map[] chan_handled:%!s(bool=true) docCreator:eugeniee-32ad-48ca-bf91-858c3a1e4588 nature:Simple channels:[0a87752e-12e5-4851-ab47-4553fddd560d eca095af-ddf2-460e-9271-e1b444a1217d 0d983307-6f46-407f-9e15-d5f081216aea 8a9fa951-3f0c-4b07-ae55-9de925bbd4e1] updateDate:%!s(float64=1.464000944e+09) _rev:1-91a16e498501a72c225ec519e67b94c1 creatorName:Eugenie note:work or not eventState:%!s(float64=100)] – db.(*Database).getChannelsAndAccess() at crud.go:795

So it crashed for all my epoch time attributes and event a simple int, btw I don’t know why all the ints are converted in float64 inside the sync gateway.

Thanks for your reply

Your sync function threw a JavaScript TypeError exception. Sounds like the function is expecting a document property to be one type, and you’ve added a document where it’s a different type. It’s important for the sync function to be defensive and handle any document a client might try to push, so you’ll need to add some defensive type checking.

The document dump in the warning shows the document as a Go data structure; Go happens to parse all JS numbers into float types. That has nothing to do with your sync function; don’t worry about it.