Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Fix error not raised when using a not defined type #178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/parser-cases/issue_177.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include "issue_177_include.thrift"

struct Issue177 {
1: issue_177_include.Status status
2: issue_177_include.invalidType type
}
4 changes: 4 additions & 0 deletions tests/parser-cases/issue_177_include.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
enum Status {
OK = 1
ERROR = 2
}
6 changes: 6 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,9 @@ def test_nest_incomplete_type():

def test_issue_121():
load('parser-cases/issue_121.thrift')


def test_issue_177():
with pytest.raises(ThriftParserError) as excinfo:
load('parser-cases/issue_177.thrift')
assert "type found: 'issue_177_include.invalidType'" in str(excinfo.value)
4 changes: 4 additions & 0 deletions thriftpy2/parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def load(path, module_name=None, include_dirs=None, include_dir=None, encoding='
include_dir=include_dir)
if incomplete_type:
fill_incomplete_ttype(thrift, thrift)
if incomplete_type:
missing_type = list(incomplete_type.values())[0][0]
msg = 'No type found: %r when parse file %r' % (missing_type, path)
raise ThriftParserError(msg)
if real_module:
sys.modules[module_name] = thrift
return thrift
Expand Down