question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enum validation fails when enum is defined in separate thrift file

See original GitHub issue

We noticed an error like this when running code gen:

E: 'One' is not a member of enum type Foo: members=[One]

with testing_foo.thrift defined as:

namespace java testing 

enum Foo {
  One = 1
}

and testing_bar.thrift defined as:

namespace java testing

include 'testing_foo.thrift'

struct Bar {
  1: required testing_foo.Foo foo = Foo.One;
}

(This happens with required testing_foo.Foo foo = Foo.One and required testing_foo.Foo foo = One)

For reference required testing_foo.Foo foo = 1 seems to work fine.

It seems like the linking happens correctly, just the validation fails.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
benjamin-badercommented, Oct 12, 2016

Just confirmed my reading using the Apache compiler:

a.thrift:

namespace java a

enum Foo {
  One
}

b.thrift:

namespace java b

struct Bar {
  1: required a.Foo foo = One
}
$ thrift -gen java b.thrift
> [FAILURE:/Users/bendb/Development/thrift/b.thrift:6] error: identifier One is unqualified!

I’ll have a fix for the initial bug, but don’t want to deviate from Apache’s behavior more than necessary; we’ll match this validation behavior.

0reactions
benjamin-badercommented, Oct 12, 2016

OK, I’ve finally got some time to address this. As I’m looking over the Apache compiler, it certainly appears that unqualified enum references in constants (e.g. required testing_foo.Foo foo = One) are not accepted; this is as of version 0.9.3. What version are you using that allows this?

t_const_value.h is approximately the same things as Thrifty’s ConstValueElement, and defines accessors used during const validation. The ones relevant to enums throw exceptions (i.e. fail) during const validation: https://github.com/apache/thrift/blob/0.9.3/compiler/cpp/src/parse/t_const_value.h#L107

How was this working for you previously?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validate Thrift Enums with constant values
I have a Thrift file that specifies an enum as follows: enum MyEnumStuff { ABC = 7, ..., XYZ = 9, ..., //...
Read more >
Thrift: The Missing Guide
Enums are specified C-style. Compiler assigns default values starting at 0. 2, You can of course, supply specific integral values for constants.
Read more >
Validations for Enum Types
Learn how to build validations for enums using Java custom ... Let's start by defining an annotation to validate the pattern of an...
Read more >
Chapter 6. Apache Thrift IDL - liveBook · Manning
In this chapter, we'll examine the features of the Apache Thrift Interface Definition Language (IDL) and learn how to use the Apache Thrift...
Read more >
Apache Thrift - Interface Description Language (IDL)
The Thrift interface definition language (IDL) allows for the definition of ... [7] Definition ::= Const | Typedef | Enum | Struct |...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found