Skip to content

Commit 0680fb4

Browse files
atulepparthea
andauthored
fix: add more context to error message. (#340)
Co-authored-by: Anthonios Partheniou <[email protected]>
1 parent ea41551 commit 0680fb4

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

google/api_core/path_template.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ def transcode(http_options, **request_kwargs):
270270
]
271271
path_args = {field: get_field(request_kwargs, field) for field in path_fields}
272272
request["uri"] = expand(uri_template, **path_args)
273-
274273
# Remove fields used in uri path from request
275274
leftovers = copy.deepcopy(request_kwargs)
276275
for path_field in path_fields:
@@ -297,4 +296,8 @@ def transcode(http_options, **request_kwargs):
297296
request["method"] = http_option["method"]
298297
return request
299298

300-
raise ValueError("Request obj does not match any template")
299+
raise ValueError(
300+
"Request {} does not match any URL path template in available HttpRule's {}".format(
301+
request_kwargs, [opt["uri"] for opt in http_options]
302+
)
303+
)

tests/unit/test_path_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ def test_transcode_with_additional_bindings(
362362
[[["get", "/v1/{name}", ""]], {"name": "first/last"}],
363363
[[["get", "/v1/{name=mr/*/*}", ""]], {"name": "first/last"}],
364364
[[["post", "/v1/{name}", "data"]], {"name": "first/last"}],
365+
[[["post", "/v1/{first_name}", "data"]], {"last_name": "last"}],
365366
],
366367
)
367368
def test_transcode_fails(http_options, request_kwargs):
@@ -385,5 +386,4 @@ def helper_test_transcode(http_options_list, expected_result_list):
385386
}
386387
if expected_result_list[2]:
387388
expected_result["body"] = expected_result_list[2]
388-
389389
return (http_options, expected_result)

0 commit comments

Comments
 (0)