Skip to content

Commit 374cdb4

Browse files
authored
fix silent crash when output from compiler is too large (#3478) (#3482)
1 parent a2c3d94 commit 374cdb4

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Sources/Build/BuildDelegate.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,18 +553,22 @@ public final class BuildDelegate: BuildSystemDelegate, SwiftCompilerOutputParser
553553
}
554554

555555
if let output = message.standardOutput {
556-
// Scoop out any errors from the output, so they can later be passed to the advice provider in case of failure.
557-
let regex = try! RegEx(pattern: #".*(error:[^\n]*)\n.*"#, options: .dotMatchesLineSeparators)
558-
for match in regex.matchGroups(in: output) {
559-
self.errorMessagesByTarget[parser.targetName] = (self.errorMessagesByTarget[parser.targetName] ?? []) + [match[0]]
560-
}
561-
556+
// first we want to print the output so users have it handy
562557
if !self.isVerbose {
563558
self.progressAnimation.clear()
564559
}
565560

566561
self.outputStream <<< output
567562
self.outputStream.flush()
563+
564+
// next we want to try and scoop out any errors from the output (if reasonable size, otherwise this will be very slow),
565+
// so they can later be passed to the advice provider in case of failure.
566+
if output.utf8.count < 1024 * 10 {
567+
let regex = try! RegEx(pattern: #".*(error:[^\n]*)\n.*"#, options: .dotMatchesLineSeparators)
568+
for match in regex.matchGroups(in: output) {
569+
self.errorMessagesByTarget[parser.targetName] = (self.errorMessagesByTarget[parser.targetName] ?? []) + [match[0]]
570+
}
571+
}
568572
}
569573
}
570574
}

0 commit comments

Comments
 (0)