10000 feat: Add more details to MissingTargetException error by di · Pull Request #158 · GoogleCloudPlatform/functions-framework-python · GitHub
[go: up one dir, main page]

Skip to content

feat: Add more details to MissingTargetException error #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/functions_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,15 @@ def handle_none(rv):

# Extract the target function from the source file
if not hasattr(source_module, target):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind syncing this PR to main branch? This line should now be in _function_registry.py.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KaylaNguyen I'm not 8000 a maintainer of this repo anymore, and thus don't have write access to this branch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Dustin, would you mind forking this repo and copy this branch to a new one on di/functions-framework-python and create a PR from that instead? Then you won't need to be a maintainer of the repo to make changes to the branch. We can add you as maintainer of this repo to proceed with these 2 commits but all admins are OOO atm.

non_target_functions = ", ".join(
"'{attr}'".format(attr=attr)
for attr in dir(source_module)
if isinstance(getattr(source_module, attr), types.FunctionType)
)

raise MissingTargetException(
"File {source} is expected to contain a function named {target}".format(
source=source, target=target
"File {source} is expected to contain a function named '{target}' (found: {non_target_functions} instead)".format(
source=source, target=target, non_target_functions=non_target_functions
)
)
function = getattr(source_module, target)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ def test_invalid_function_definition_multiple_entry_points():
create_app(target, source, "event")

assert re.match(
"File .* is expected to contain a function named function", str(excinfo.value)
"File .* is expected to contain a function named 'function' \(found: 'fun', 'myFunctionBar', 'myFunctionFoo' instead\)",
str(excinfo.value),
)


Expand All @@ -289,7 +290,7 @@ def test_invalid_function_definition_multiple_entry_points_invalid_function():
create_app(target, source, "event")

assert re.match(
"File .* is expected to contain a function named invalidFunction",
"File .* is expected to contain a function named 'invalidFunction' \(found: 'fun', 'myFunctionBar', 'myFunctionFoo' instead\)",
str(excinfo.value),
)

Expand Down
0