MCPcopy
hub / github.com/syncthing/syncthing / copyStderr

Function copyStderr

cmd/syncthing/monitor.go:217–264  ·  view source on GitHub ↗
(stderr io.Reader, dst io.Writer)

Source from the content-addressed store, hash-verified

215}
216
217func copyStderr(stderr io.Reader, dst io.Writer) {
218 br := bufio.NewReader(stderr)
219
220 var panicFd *os.File
221 defer func() {
222 if panicFd != nil {
223 _ = panicFd.Close()
224 maybeReportPanics()
225 }
226 }()
227
228 for {
229 line, err := br.ReadString('\n')
230 if err != nil {
231 return
232 }
233
234 dst.Write([]byte(line))
235
236 if panicFd == nil && (strings.HasPrefix(line, "panic:") || strings.HasPrefix(line, "fatal error:") || strings.HasPrefix(line, "runtime:")) {
237 panicFd, err = os.Create(locations.GetTimestamped(locations.PanicLog))
238 if err != nil {
239 slog.Error("Failed to create panic log", slogutil.Error(err))
240 continue
241 }
242
243 slog.Error("Panic detected, writing to file", slogutil.FilePath(panicFd.Name()))
244 slog.Info("Please check for existing issues with similar panic message at https://github.com/syncthing/syncthing/issues/")
245 slog.Info("If no issue with similar panic message exists, please create a new issue with the panic log attached")
246
247 stdoutMut.Lock()
248 for _, line := range stdoutFirstLines {
249 panicFd.WriteString(line)
250 }
251 panicFd.WriteString("...\n")
252 for _, line := range stdoutLastLines {
253 panicFd.WriteString(line)
254 }
255 stdoutMut.Unlock()
256
257 panicFd.WriteString("Panic at " + time.Now().Format(time.RFC3339) + "\n")
258 }
259
260 if panicFd != nil {
261 panicFd.WriteString(line)
262 }
263 }
264}
265
266func copyStdout(stdout io.Reader, dst io.Writer) {
267 br := bufio.NewReader(stdout)

Callers 1

monitorMainMethod · 0.85

Calls 11

NameMethod · 0.95
GetTimestampedFunction · 0.92
ErrorFunction · 0.92
FilePathFunction · 0.92
maybeReportPanicsFunction · 0.85
UnlockMethod · 0.80
CloseMethod · 0.65
CreateMethod · 0.65
ErrorMethod · 0.65
NowMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected