Skip to content

Commit 6bcb7e2

Browse files
joe4devclaude
andcommitted
fix(init): emit captured logs verbatim; do not rewrite bare CR to LF
Commit 9b54e66 rewrote every bare carriage return in the captured runtime output to a line feed, intending to render multi-line init tracebacks across lines. But AWS keeps a bare CR inside a single CloudWatch log event (records split on LF only), and LocalStack's log ingestion likewise splits on "\n". The conversion therefore wrongly split any record containing a bare CR into multiple events, breaking the AWS-validated TestCloudwatchLogs::test_multi_line_prints (a user `print("a\rb")` was emitted as two events "a" and "b" instead of one event "a\rb"). Emit the runtime output verbatim. Verified: test_multi_line_prints and the full TestLambdaErrors suite (incl. the runtime-exit/segfault error-reporting tests) are both green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent b350b50 commit 6bcb7e2

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

cmd/localstack/logs.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,13 @@ func (lc *LogCollector) reset() {
3838
func (lc *LogCollector) getLogs() lsapi.LogResponse {
3939
lc.mutex.Lock()
4040
defer lc.mutex.Unlock()
41-
logs := strings.Join(lc.RuntimeLogs, "")
42-
// The runtime emits multi-line records (e.g. an unhandled-init traceback) as a single log
43-
// frame with internal newlines replaced by bare carriage returns. AWS renders those back as
44-
// line feeds, so convert bare CR to LF while preserving genuine CRLF line endings (which AWS
45-
// keeps verbatim, e.g. the LAMBDA_WARNING line).
46-
const crlfPlaceholder = "\x00"
47-
logs = strings.ReplaceAll(logs, "\r\n", crlfPlaceholder)
48-
logs = strings.ReplaceAll(logs, "\r", "\n")
49-
logs = strings.ReplaceAll(logs, crlfPlaceholder, "\r\n")
41+
// Emit the captured runtime output verbatim. Do NOT rewrite bare carriage returns to line
42+
// feeds: AWS keeps a bare CR inside a single CloudWatch log event (it splits records on LF
43+
// only), so a user `print("a\rb")` must stay the one event "a\rb". LocalStack's log ingestion
44+
// likewise splits on "\n" (see services/lambda_/.../logs.py), so converting CR to LF here
45+
// would wrongly split such records — see TestCloudwatchLogs::test_multi_line_prints.
5046
response := lsapi.LogResponse{
51-
Logs: logs,
47+
Logs: strings.Join(lc.RuntimeLogs, ""),
5248
}
5349
lc.RuntimeLogs = []string{}
5450
return response

0 commit comments

Comments
 (0)