YahooArchive / mojito

[archiving soon] Yahoo! Mojito Framework
BSD 3-Clause "New" or "Revised" License
1.57k stars 214 forks source link

ac.error() sends an empty response to binder #1379

Open selkovjr opened 10 years ago

selkovjr commented 10 years ago

I have a mojit with a binder that tunnels a database query to its server-side controller. In the binder, the response is processed by a ModelList hooked to a DataTable. Everything works fine as long as there are no errors in the database. In the case of an error, everything works up to the point when the controller calls ac.error(err), where err has the following form (as I get it from pg and as rendered by console.log in the server):

{ [error: column "test" does not exist]
  name: 'error',
  length: 97,
  severity: 'ERROR',
  code: '42703',
  detail: undefined,
  hint: undefined,
  position: '56',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  file: 'parse_relation.c',
  line: '2655',
  routine: 'errorMissingColumn' }

I haven't tracked all the goings-on between the call to ac.error() and the moment when stuff gets written to the socket, but at the other end of it, I see

POST http://bfs.observercentral.net/tunnel 42703 (unknown) io-base.js:737
IO.send io-base.js:737
Y.io io-base.js:903
TunnelClient._makeRequest mojito-tunnel-client.js:74
TunnelClient.rpc mojito-tunnel-client.js:68
Y.namespace.Dispatcher.rpc mojito-dispatcher.js:150
(anonymous function) mojito-dispatcher.js:216
(anonymous function) mojito-client-store.js:223
retrieveFile mojito-client-store.js:84
ClientStore._getType mojito-client-store.js:346
ClientStore.expandInstanceForEnv mojito-client-store.js:190
ClientStore.expandInstance mojito-client-store.js:152
Y.namespace.Dispatcher.dispatch mojito-dispatcher.js:196
MojitoClient.executeAction mojito-client.js:684
MojitoClient.init.Y.Array.each.(anonymous function) mojito-client.js:427
MojitProxy.invoke mojito-mojit-proxy.js:275

while mojito-output-buffer reports:

error: (mojito-output-buffer): Error executing: 'undefined':
error: (mojito-output-buffer): column "test" does not exist
error: (mojito-output-buffer): 
error: column "test" does not exist
    at Connection.parseE (/home/bfs/mojito/bfs/node_modules/pg/lib/connection.js:526:11)
    at Connection.parseMessage (/home/bfs/mojito/bfs/node_modules/pg/lib/connection.js:356:17)
    at Socket.<anonymous> (/home/bfs/mojito/bfs/node_modules/pg/lib/connection.js:105:22)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:745:14)
    at Socket.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:407:10)
    at emitReadable (_stream_readable.js:403:5)
    at readableAddChunk (_stream_readable.js:165:9)
    at Socket.Readable.push (_stream_readable.js:127:10)

This raises a few questions:

server transaction error: Unexpected token u yui-base.js:5779
INSTANCE.log yui-base.js:5779
(anonymous function) SamplesBinderIndex.js:843
Y.Subscriber._notify event-custom-base.js:1313
Y.Subscriber.notify event-custom-base.js:1342
Y.CustomEvent._notify event-custom-base.js:1005
Y.CustomEvent._procSubs event-custom-base.js:1131
CEProto.fireComplex event-custom-complex.js:230
Y.CustomEvent._fire event-custom-base.js:1078
ET.fire event-custom-base.js:2233
(anonymous function) model-list.js:612
(anonymous function) SamplesBinderIndex.js:245
OutputHandler.error mojito-output-handler.js:169
TunnelClient.rpc.cfg.on.failure mojito-tunnel-client.js:58

I will appreciate any clues for how to debug it further, or for how to do it right.

aljimenez commented 10 years ago

Thanks for pointing this out. The OutputBuffer's undefined id is definitely something we should fix; there are a couple of places where error messages can be more clear. I am not sure what is going on exactly, but I will try to setup a test case where there is a tunnel call that ends up calling ac.error. Mojito should be able to handle passing an object to ac.error. The best way to debug what is going on is to go through the call stack within ac.error and see where the response is getting malformed resulting it what seems to be a JSON parse error.