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

Jens Geyer resolved THRIFT-5947.
--------------------------------
    Fix Version/s: 0.24.0
       Resolution: Fixed

Thanks Antoine Lafarge

> Exception has occurred: Error: writeString called without a string/Buffer 
> argument: [object Object]
> ---------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-5947
>                 URL: https://issues.apache.org/jira/browse/THRIFT-5947
>             Project: Thrift
>          Issue Type: Bug
>          Components: JavaScript - Compiler
>            Reporter: Jens Geyer
>            Assignee: Jens Geyer
>            Priority: Major
>             Fix For: 0.24.0
>
>         Attachments: screenshot-1.png
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> There is a bug in the JavaScript custom exception constructor implementation.
> This thrift custom exception :
> {code}
> exception CustomError {
>   1: required ErrorCode code;
> }
> {code}
> results to a constructor which takes a single JS Object with custom 
> properties :
> {code}
> const CustomError = module.exports.CustomError = class extends 
> Thrift.TException {
>   constructor(args) {
>     super(args);
>     this.name = "CustomError";
>     this.code = null;
>     // ...
> {code}
> We can check it in the associated TypeScript typings :
> {code}
> declare class ZaapError extends Thrift.TException {
>     public code: ErrorCode;
>       constructor(args?: { code: ErrorCode; });
>   }
> {code}
> The generated code gives the JS object to the constructor of 
> Thrift.TException.
> But the Thrift.TException constructor takes a single string argument :
> {code}
> exports.TException = TException;
> function TException(message) {
>   Error.call(this);
>   Error.captureStackTrace(this, this.constructor);
>   this.name = this.constructor.name;
>   this.message = message;
> };
> util.inherits(TException, Error);
> {code}
> Giving this custom object to the TException (instead of a string) throws 
> unwanted Thrift exceptions in TBinaryProtocol.prototype.writeStringOrBinary :
> {code}
> Exception has occurred: Error: writeString called without a string/Buffer 
> argument: [object Object]
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to