Skip to content

Commit

Permalink
fix: don't exit on reload if there is a syntax error (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
alsuren committed Dec 21, 2022
1 parent ccc6747 commit fcf59c8
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/functions_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,27 @@ def handle_none(rv):

# Execute the module, within the application context
with _app.app_context():
spec.loader.exec_module(source_module)
try:
spec.loader.exec_module(source_module)
function = _function_registry.get_user_function(source, source_module, target)
except Exception as e:
if werkzeug.serving.is_running_from_reloader():
# When reloading, print out the error immediately, but raise
# it later so the debugger or server can handle it.
import traceback
traceback.print_exc()
err = e

def function(*_args, **_kwargs):
raise err from None

else:
# When not reloading, raise the error immediately so the
# command fails.
raise e from None

# Get the configured function signature type
signature_type = _function_registry.get_func_signature_type(target, signature_type)
function = _function_registry.get_user_function(source, source_module, target)

_configure_app(_app, function, signature_type)

Expand Down

0 comments on commit fcf59c8

Please sign in to comment.