MCPcopy Create free account
hub / github.com/bracesdev/errtrace / parseLogOutput

Function parseLogOutput

cmd/errtrace/main_test.go:894–935  ·  view source on GitHub ↗
(file, s string)

Source from the content-addressed store, hash-verified

892}
893
894func parseLogOutput(file, s string) ([]logLine, error) {
895 var logs []logLine
896 for _, line := range strings.Split(s, "\n") {
897 if line == "" {
898 continue
899 }
900
901 // Drop the path so we can determinstically split on ":" (which is a valid character in Windows paths).
902 line = strings.TrimPrefix(line, file)
903 parts := strings.SplitN(line, ":", 4)
904 if len(parts) != 4 {
905 return nil, errtrace.Wrap(fmt.Errorf("bad log line: %q", line))
906 }
907
908 var msg string
909 if len(parts) == 4 {
910 if _, err := strconv.Atoi(parts[2]); err == nil {
911 // file:line:column:msg
912 msg = parts[3]
913 }
914 }
915 if msg == "" && len(parts) >= 2 {
916 // file:line:msg
917 msg = strings.Join(parts[2:], ":")
918 }
919 if msg == "" {
920 return nil, errtrace.Wrap(fmt.Errorf("bad log line: %q", line))
921 }
922
923 lineNum, err := strconv.Atoi(parts[1])
924 if err != nil {
925 return nil, errtrace.Wrap(fmt.Errorf("bad log line: %q", line))
926 }
927
928 logs = append(logs, logLine{
929 Line: lineNum,
930 Msg: msg,
931 })
932 }
933
934 return logs, nil
935}
936
937func chdir(t testing.TB, dir string) (restore func()) {
938 t.Helper()

Callers 1

testGoldenContentsFunction · 0.85

Calls 1

WrapFunction · 0.92

Tested by

no test coverage detected