Skip to content

Commit b58f840

Browse files
Raise what field is missing in ES assert error.
1 parent 1f2267c commit b58f840

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

biothings/web/query/formatter.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,15 @@ def __init__(self, *args, **kwargs):
8686
super().__init__(*args, **kwargs)
8787
# make sure the document is coming from
8888
# elasticsearch at initialization time
89-
assert "hits" in self.data
90-
assert "total" in self.data["hits"]
91-
assert "hits" in self.data["hits"]
89+
if "hits" not in self.data:
90+
raise ValueError("Response missing 'hits' field")
91+
if "total" not in self.data["hits"]:
92+
raise ValueError("Response missing 'hits.total' field")
93+
if "hits" not in self.data["hits"]:
94+
raise ValueError("Response missing 'hits.hits' field")
9295
for hit in self.data["hits"]["hits"]:
93-
assert "_source" in hit
96+
if "_source" not in hit:
97+
raise ValueError("Hit missing '_source' field")
9498

9599
class _Doc(Doc):
96100
pass

0 commit comments

Comments
 (0)