Chandler May created THRIFT-5674: ------------------------------------ Summary: Server implementation exceptions are not sent to client in ES6 promise-style invocation Key: THRIFT-5674 URL: https://issues.apache.org/jira/browse/THRIFT-5674 Project: Thrift Issue Type: Bug Components: JavaScript - Compiler Affects Versions: 0.17.0 Environment: Discovered on Node.js v16.13.2, Thrift 0.17.0 compiler, 0.16.0 library.
Reproduced on Node.js v10.19.0, Thrift 0.17.0 compiler, 0.17.0 library (just what I happened to have available for trying out the tutorial code). Reporter: Chandler May When a server implementation throws a user-defined exception, the server crashes and the exception is not sent to the client. I believe this issue only happens in the Promise-style invocation of code generated for ES6. Specifically, I think it arises from this line: [https://github.com/apache/thrift/blob/0.17.0/compiler/cpp/src/thrift/generate/t_js_generator.cc#L1484] Generated code looks like the following (generated from the Calculator.calculate example): {code:java} Promise.resolve(this._handler.calculate.bind(this._handler)( args.logid, args.w )).then( ... ).catch(err => { if (err instanceof ttypes.InvalidOperation) { ... } );{code} The implementation-generated exception is handled by the promise chain. The problem is that the implementation (handler) method is called _before_ Promise.resolve, so any exception it throws is not handled by the promise chain. So, when running* NodeServerPromise.js and NodeClientPromise.js from the tutorial, the server crashes when InvalidOperation is thrown and the client does not receive InvalidOperation (or anything further). I think the minimal fix would be to generate something like the following instead: {code:java} new Promise((resolve) => resolve(this._handler.calculate.bind(this._handler)( args.logid, args.w ))).then( ... ).catch(err => { if (err instanceof ttypes.InvalidOperation) { ... } );{code} When making this change on the generated tutorial code and re-running* the server and client, the server stays up and both the server and client log five lines, as expected. * There also seems to be a couple of errors in NodeClientPromise.js in the tutorial coderi. I had to change "fail" to "catch" and "fin" to "finally" to get it to work. -- This message was sent by Atlassian Jira (v8.20.10#820010)