You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Jens Geyer (Jira)" <ji...@apache.org> on 2023/03/01 23:13:00 UTC

[jira] [Resolved] (THRIFT-5674) Server implementation exceptions are not sent to client in ES6 promise-style invocation

     [ https://issues.apache.org/jira/browse/THRIFT-5674?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jens Geyer resolved THRIFT-5674.
--------------------------------
    Fix Version/s: 0.19.0
         Assignee: Chandler May  (was: Jens Geyer)
       Resolution: Fixed

> 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
>            Assignee: Chandler May
>            Priority: Major
>             Fix For: 0.19.0
>
>   Original Estimate: 3h
>          Time Spent: 20m
>  Remaining Estimate: 2h 40m
>
> 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{^}1{^} 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{^}1{^} the server and client, the server stays up and both the server and client log five lines, as expected.
> _[1] There also seems to be a couple of errors in NodeClientPromise.js in the tutorial code.  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)