Improve error reporting for missing index
This commit is contained in:
parent
3a42079ec7
commit
704a12146b
@ -438,9 +438,12 @@ class DynamoHandler(BaseResponse):
|
|||||||
all_indexes = (table.global_indexes or []) + (table.indexes or [])
|
all_indexes = (table.global_indexes or []) + (table.indexes or [])
|
||||||
indexes_by_name = dict((i["IndexName"], i) for i in all_indexes)
|
indexes_by_name = dict((i["IndexName"], i) for i in all_indexes)
|
||||||
if index_name not in indexes_by_name:
|
if index_name not in indexes_by_name:
|
||||||
raise ValueError(
|
er = "com.amazonaws.dynamodb.v20120810#ResourceNotFoundException"
|
||||||
"Invalid index: %s for table: %s. Available indexes are: %s"
|
return self.error(
|
||||||
% (index_name, name, ", ".join(indexes_by_name.keys()))
|
er,
|
||||||
|
"Invalid index: {} for table: {}. Available indexes are: {}".format(
|
||||||
|
index_name, name, ", ".join(indexes_by_name.keys())
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
index = indexes_by_name[index_name]["KeySchema"]
|
index = indexes_by_name[index_name]["KeySchema"]
|
||||||
|
@ -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(
|
dynamodb.query(
|
||||||
TableName="test",
|
TableName="test",
|
||||||
IndexName="non_exists_index",
|
IndexName="non_exists_index",
|
||||||
KeyConditionExpression="CarModel=M",
|
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"
|
"Invalid index: non_exists_index for table: test. Available indexes are: test_gsi"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user