Skip to content

Commit 3ea87fe

Browse files
authored
Add error handling if lambda logs are not received from the environment (#12521)
1 parent 072c810 commit 3ea87fe

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

localstack-core/localstack/services/lambda_/invocation/version_manager.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,20 @@ def invoke(self, *, invocation: Invocation) -> InvocationResult:
238238
)
239239
# TODO: consider using the same prefix logging as in error case for execution environment.
240240
# possibly as separate named logger.
241-
LOG.debug("Got logs for invocation '%s'", invocation.request_id)
242-
for log_line in invocation_result.logs.splitlines():
243-
LOG.debug(
244-
"[%s-%s] %s",
245-
function_id.function_name,
241+
if invocation_result.logs is not None:
242+
LOG.debug("Got logs for invocation '%s'", invocation.request_id)
243+
for log_line in invocation_result.logs.splitlines():
244+
LOG.debug(
245+
"[%s-%s] %s",
246+
function_id.function_name,
247+
invocation.request_id,
248+
truncate(log_line, config.LAMBDA_TRUNCATE_STDOUT),
249+
)
250+
else:
251+
LOG.warning(
252+
"[%s] Error while printing logs for function '%s': Received no logs from environment.",
246253
invocation.request_id,
247-
truncate(log_line, config.LAMBDA_TRUNCATE_STDOUT),
254+
function_id.function_name,
248255
)
249256
return invocation_result
250257

@@ -260,7 +267,8 @@ def store_logs(
260267
self.log_handler.add_logs(log_item)
261268
else:
262269
LOG.warning(
263-
"Received no logs from invocation with id %s for lambda %s",
270+
"Received no logs from invocation with id %s for lambda %s. Execution environment logs: \n%s",
264271
invocation_result.request_id,
265272
self.function_arn,
273+
execution_env.get_prefixed_logs(),
266274
)

0 commit comments

Comments
 (0)