creditkarma / thrift-typescript

Generate TypeScript from Thrift IDL files
Apache License 2.0
155 stars 32 forks source link

Namespace of Exception types not being used correctly #153

Closed VincentNewkirk closed 5 years ago

VincentNewkirk commented 5 years ago

Using the --file-per-type option and given this IDL:

exception DonatelloException {
  1: string message
}

exception DruidException {
  1: string message
}

service DruidQueryService {

  QueryResult adhocQuery(
    2: required string          serviceGroup,
  ) throws (
    1: DonatelloException            donatelloException,
    2: DruidException                druidException,
  ),

Produces this:

        }).catch((err: Error): void => {
          if (err instanceof DonatelloException) {
                const result: AdhocQueryResult = new AdhocQueryResult({ donatelloException: err });
                output.writeMessageBegin("adhocQuery", thrift.Thrift.MessageType.REPLY, requestId);
                result.write(output);
                output.writeMessageEnd();
                output.flush();
                return;
            }
            else if (err instanceof DruidException) {
                const result: AdhocQueryResult = new AdhocQueryResult({ druidException: err });
                output.writeMessageBegin("adhocQuery", thrift.Thrift.MessageType.REPLY, requestId);
                result.write(output);
                output.writeMessageEnd();
                output.flush();
                return;
            }

The problem is that DonatelloException and DruidException are both undefined. This problem is solves by appending __NAMESPACE__. to both these exceptions.

DonatelloException -> __NAMESPACE__.DonatelloExcption
kevin-greene-ck commented 5 years ago

Fixed in 3.4.1