Skip to content

Commit 0e704a2

Browse files
committed
fix: improve file path matching in error message
1 parent 795aabd commit 0e704a2

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

journald.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"os/exec"
1111
"path"
12+
"regexp"
1213
"strings"
1314

1415
"github.com/spf13/cobra"
@@ -111,12 +112,23 @@ func shouldTriggerError(entry LogEntry) bool {
111112
return strings.Contains(entry.Message, "vfs cache: failed to upload")
112113
}
113114

115+
var fileNameRegex = regexp.MustCompile(`ERROR\s+:\s+(.+?):\s`)
116+
117+
func fileNameFromEntry(entry LogEntry) string {
118+
s := fileNameRegex.FindStringSubmatch(entry.Message)
119+
if len(s) < 2 {
120+
return ""
121+
}
122+
fmt.Println(s)
123+
return s[1]
124+
}
125+
114126
func handleLogEntry(entry LogEntry, driveName string) {
115127
if !shouldTriggerError(entry) {
116128
return
117129
}
118130

119-
fileName := strings.TrimSpace(strings.SplitN(entry.Message, ":", 3)[1])
131+
fileName := fileNameFromEntry(entry)
120132
filePath := fileNameToPath(driveName, fileName)
121133

122134
// make sure file still exists

journald_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,30 @@ func TestShouldTriggerError(t *testing.T) {
146146
assert.Equalf(t, tt.want, got, "%s: shouldTriggerError() = %v, want %v", tt.name, got, tt.want)
147147
}
148148
}
149+
150+
func TestFileNameFromEntry(t *testing.T) {
151+
for _, test := range []struct {
152+
name string
153+
message string
154+
}{
155+
{
156+
name: "test",
157+
message: "ERROR : test: vfs cache: failed to upload try #3, will retry in 40s: vfs cache: failed to transfer file from cache to remote: googleapi: Error 403: Insufficient permissions for the specified parent., insufficientParentPermissions",
158+
},
159+
{
160+
name: "/",
161+
message: "ERROR : /: Dir.Mkdir failed to create directory: failed to make directory: googleapi: Error 403: Insufficient permissions for the specified parent., insufficientParentPermissions",
162+
},
163+
{
164+
name: "blatest.test",
165+
message: "Mai 21 11:26:12 psigma rclone[270244]: 2025/05/21 11:26:12 ERROR : blatest.test: vfs cache: failed to upload try #4, will retry in 1m20s: vfs cache: failed to transfer file from cache to remote: googleapi: Error 403: Insufficient permissions for the specified parent., insufficientParentPermissions",
166+
},
167+
{
168+
name: "",
169+
message: "something anything nothing",
170+
},
171+
} {
172+
n := fileNameFromEntry(LogEntry{Message: test.message})
173+
assert.Equal(t, test.name, n)
174+
}
175+
}

0 commit comments

Comments
 (0)