Skip to content

Commit 8eb69db

Browse files
committed
feat: Add more details to MissingTargetException error
1 parent 455affd commit 8eb69db

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/functions_framework/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,15 @@ def handle_none(rv):
256256

257257
# Extract the target function from the source file
258258
if not hasattr(source_module, target):
259+
non_target_functions = ", ".join(
260+
"'{attr}'".format(attr=attr)
261+
for attr in dir(source_module)
262+
if isinstance(getattr(source_module, attr), types.FunctionType)
263+
)
264+
259265
raise MissingTargetException(
260-
"File {source} is expected to contain a function named {target}".format(
261-
source=source, target=target
266+
"File {source} is expected to contain a function named '{target}' (found: {non_target_functions} instead)".format(
267+
source=source, target=target, non_target_functions=non_target_functions
262268
)
263269
)
264270
function = getattr(source_module, target)

tests/test_functions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ def test_invalid_function_definition_multiple_entry_points():
277277
create_app(target, source, "event")
278278

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

283284

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

291292
assert re.match(
292-
"File .* is expected to contain a function named invalidFunction",
293+
"File .* is expected to contain a function named 'invalidFunction' \(found: 'fun', 'myFunctionBar', 'myFunctionFoo' instead\)",
293294
str(excinfo.value),
294295
)
295296

0 commit comments

Comments
 (0)