Skip to content

Commit

Permalink
fix: add more context to error message. (#340)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
  • Loading branch information
atulep and parthea committed Mar 9, 2022
1 parent ea41551 commit 0680fb4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions google/api_core/path_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ def transcode(http_options, **request_kwargs):
]
path_args = {field: get_field(request_kwargs, field) for field in path_fields}
request["uri"] = expand(uri_template, **path_args)

# Remove fields used in uri path from request
leftovers = copy.deepcopy(request_kwargs)
for path_field in path_fields:
Expand All @@ -297,4 +296,8 @@ def transcode(http_options, **request_kwargs):
request["method"] = http_option["method"]
return request

raise ValueError("Request obj does not match any template")
raise ValueError(
"Request {} does not match any URL path template in available HttpRule's {}".format(
request_kwargs, [opt["uri"] for opt in http_options]
)
)
2 changes: 1 addition & 1 deletion tests/unit/test_path_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ def test_transcode_with_additional_bindings(
[[["get", "/v1/{name}", ""]], {"name": "first/last"}],
[[["get", "/v1/{name=mr/*/*}", ""]], {"name": "first/last"}],
[[["post", "/v1/{name}", "data"]], {"name": "first/last"}],
[[["post", "/v1/{first_name}", "data"]], {"last_name": "last"}],
],
)
def test_transcode_fails(http_options, request_kwargs):
Expand All @@ -385,5 +386,4 @@ def helper_test_transcode(http_options_list, expected_result_list):
}
if expected_result_list[2]:
expected_result["body"] = expected_result_list[2]

return (http_options, expected_result)

0 comments on commit 0680fb4

Please sign in to comment.