Skip to content

Commit

Permalink
force recreate when detect broken cache file
Browse files Browse the repository at this point in the history
  • Loading branch information
ryodocx committed Sep 2, 2022
1 parent 8545509 commit 5d6e7cf
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cmd/kcc-cache/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ func main() {
}
if len(bytes) > 0 {
if err := json.Unmarshal(bytes, &cacheFile); err != nil {
fatal("json.Unmarshal() failed(read cache file): %s", err)
log("json.Unmarshal() failed(read cache file): %s\n...Corruption detected, recreate cache file", err)
updated = true
}
}
defer func() {
Expand Down Expand Up @@ -171,6 +172,8 @@ func main() {
}

func fatal(format string, v ...any) {
log(format, v...)

var commit string = "main"
if i, ok := debug.ReadBuildInfo(); ok {
for _, v := range i.Settings {
Expand All @@ -180,9 +183,12 @@ func fatal(format string, v ...any) {
}
}
_, _, line, _ := runtime.Caller(1)
fmt.Fprintf(os.Stderr, "error occurred at: https://github.com/ryodocx/kube-credential-cache/blob/%s/cmd/kcc-cache/main.go#L%d\n", commit, line)

os.Exit(1)
}

func log(format string, v ...any) {
fmt.Fprintf(os.Stderr, "%s: ", path.Base(os.Args[0]))
fmt.Fprintf(os.Stderr, format+"\n", v...)
fmt.Fprintf(os.Stderr, "error occurred at: https://github.com/ryodocx/kube-credential-cache/blob/%s/cmd/kcc-cache/main.go#L%d\n", commit, line)
os.Exit(1)
}

0 comments on commit 5d6e7cf

Please sign in to comment.