horizon icon indicating copy to clipboard operation
horizon copied to clipboard

Insert throws Unhandled error in request

Open almstrand opened this issue 8 years ago • 0 comments

It is not well documented that documents in the users table must define a groups property. The earlier CLI document (https://github.com/rethinkdb/horizon-docs/pull/106/commits/bcbc1a3de614d9247a223965092d443036ea95da) and several independent sources online suggest adding users like so:

horizon('users').store({id: '4C720BD1-2729-46BA-9213-ED84DEDE3120'});

If a user is added that way, without a groups property, and Horizon is initialized as follows ...

var horizon = Horizon({authType: { token: '...'}});

... the server throws an exception when e.g. attempting to insert a document to a table:

Horizon ready for connections
debug: Handling HTTP request to horizon subpath: horizon.js
debug: Client connection established.
debug: Handling HTTP request to horizon subpath: horizon.js.map
debug: Received handshake: {"request_id":0,"method":"token","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpZCI6InRtcCIsInByb3ZpZGVyIjpudWxsLCJpYXQiOjE0NzM5OTU5MDIsImV4cCI6MTQ3NDA4MjMwMn0.a6FrjflkIMoommv8wGuilz0UrXtPNV7RuSl_bX_w3GUpyZI2BbQpDzJgk-cC_q0adwOEDgDVgheybzwG8-hlLg"}
debug: Sending response: {"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpZCI6InRtcCIsInByb3ZpZGVyIjpudWxsLCJpYXQiOjE0NzM5OTU5MDIsImV4cCI6MTQ3NDA4MjMwMn0.a6FrjflkIMoommv8wGuilz0UrXtPNV7RuSl_bX_w3GUpyZI2BbQpDzJgk-cC_q0adwOEDgDVgheybzwG8-hlLg","id":"tmp","provider":null,"request_id":0}
debug: Received request from client: {"request_id":1,"type":"store","options":{"collection":"test","data":[{"id":1}]}}
debug: Unhandled error in request: TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined
    at Request.evaluate_rules (/usr/local/lib/node_modules/horizon/node_modules/@horizon/server/src/request.js:20:41)
    at new Request (/usr/local/lib/node_modules/horizon/node_modules/@horizon/server/src/request.js:12:10)
    at Client.handle_request (/usr/local/lib/node_modules/horizon/node_modules/@horizon/server/src/client.js:159:21)
    at /usr/local/lib/node_modules/horizon/node_modules/@horizon/server/src/client.js:107:47
    at Client.error_wrap_socket (/usr/local/lib/node_modules/horizon/node_modules/@horizon/server/src/client.js:50:7)
    at WebSocket.<anonymous> (/usr/local/lib/node_modules/horizon/node_modules/@horizon/server/src/client.js:107:18)
    at emitTwo (events.js:100:13)
    at WebSocket.emit (events.js:185:7)
    at Receiver.ontext (/usr/local/lib/node_modules/horizon/node_modules/ws/lib/WebSocket.js:841:10)
    at /usr/local/lib/node_modules/horizon/node_modules/ws/lib/Receiver.js:536:18
    at /usr/local/lib/node_modules/horizon/node_modules/ws/lib/Receiver.js:368:7
    at /usr/local/lib/node_modules/horizon/node_modules/ws/lib/PerMessageDeflate.js:249:5
    at afterWrite (_stream_writable.js:355:3)
    at onwrite (_stream_writable.js:346:7)
    at WritableState.onwrite (_stream_writable.js:89:5)
    at afterTransform (_stream_transform.js:79:3)
    at TransformState.afterTransform (_stream_transform.js:54:12)
    at Zlib.callback (zlib.js:613:5)
debug: Closing client connection with message: Unhandled error: TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined
debug: info: {"request_id":null,"error":"Unhandled error: TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined","error_code":0}
debug: Client connection terminated.

It seems the CLI documentation can be improved in this regard, to detail how users can be added to the table after executing hz make-token [user] (https://github.com/rethinkdb/horizon-docs/issues/121) but perhaps this exception should also be avoided in the server code by not iterating over users with no groups defined, or perhaps implicitly assigning the default group?

almstrand avatar Sep 16 '16 03:09 almstrand