Search code examples
thriftidl

Thrift syntax error


Thrift 0.9.2 here. Here is my simple led.thrift file:

namespace c_glib com.example.led
namespace java com.example.led

typedef i32 int

enum LedState {
    Off = 0,
    On = 1
}

struct LedToggleCommand {
    1: required int ledId;
    2: required LedState state;
}

exception LedUnavailableException {
    1: message;
    2: cause;
}

service LedService {
    oneway void toggle(1: LedToggleCommand cmd) throws (1: LedUnavailableException luex);
}

When I run thrift --gen java led.thrift I get the following error:

[ERROR:/Users/myuser/tmp/thrift_samples/samples/led.thrift:17] (last token was ';')
syntax error
[FAILURE:/Users/myuser/tmp/thrift_samples/samples/led.thrift:17] Parser error during include pass.

What's going on here?


Solution

  • You need to add some data types.

    exception LedUnavailableException {
        1: string message;
        2: string cause;
    }
    

    Additionally, (at least) newer versions will tell you that ...

    [FAILURE:test.thrift:22] Oneway methods can't throw exceptions.