Skip to content

Commit fcf59c8

Browse files
author
David Laban
committed
fix: don't exit on reload if there is a syntax error (#213)
1 parent ccc6747 commit fcf59c8

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/functions_framework/__init__.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,27 @@ def handle_none(rv):
350350

351351
# Execute the module, within the application context
352352
with _app.app_context():
353-
spec.loader.exec_module(source_module)
353+
try:
354+
spec.loader.exec_module(source_module)
355+
function = _function_registry.get_user_function(source, source_module, target)
356+
except Exception as e:
357+
if werkzeug.serving.is_running_from_reloader():
358+
# When reloading, print out the error immediately, but raise
359+
# it later so the debugger or server can handle it.
360+
import traceback
361+
traceback.print_exc()
362+
err = e
363+
364+
def function(*_args, **_kwargs):
365+
raise err from None
366+
367+
else:
368+
# When not reloading, raise the error immediately so the
369+
# command fails.
370+
raise e from None
354371

355372
# Get the configured function signature type
356373
signature_type = _function_registry.get_func_signature_type(target, signature_type)
357-
function = _function_registry.get_user_function(source, source_module, target)
358374

359375
_configure_app(_app, function, signature_type)
360376

0 commit comments

Comments
 (0)