Improve error reporting for missing index

This commit is contained in:
Ilya Shmygol 2019-12-12 10:49:07 +01:00
parent 3a42079ec7
commit 704a12146b
2 changed files with 9 additions and 5 deletions

View File

@ -438,9 +438,12 @@ class DynamoHandler(BaseResponse):
all_indexes = (table.global_indexes or []) + (table.indexes or [])
indexes_by_name = dict((i["IndexName"], i) for i in all_indexes)
if index_name not in indexes_by_name:
raise ValueError(
"Invalid index: %s for table: %s. Available indexes are: %s"
% (index_name, name, ", ".join(indexes_by_name.keys()))
er = "com.amazonaws.dynamodb.v20120810#ResourceNotFoundException"
return self.error(
er,
"Invalid index: {} for table: {}. Available indexes are: {}".format(
index_name, name, ", ".join(indexes_by_name.keys())
),
)
index = indexes_by_name[index_name]["KeySchema"]

View File

@ -2655,14 +2655,15 @@ def test_query_by_non_exists_index():
],
)
with assert_raises(ValueError) as ex:
with assert_raises(ClientError) as ex:
dynamodb.query(
TableName="test",
IndexName="non_exists_index",
KeyConditionExpression="CarModel=M",
)
str(ex.exception).should.equal(
ex.exception.response["Error"]["Code"].should.equal("ResourceNotFoundException")
ex.exception.response["Error"]["Message"].should.equal(
"Invalid index: non_exists_index for table: test. Available indexes are: test_gsi"
)