Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(go): avoid formatting protos via %v for non-debug uses #5673

Merged
merged 1 commit into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions kythe/go/platform/kzip/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func NewAccumulator(fileSize int64) *Accumulator {
}
}

func cuString(u *kzip.Unit) string {
return fmt.Sprintf("corpus: %q root: %q language: %q", u.Proto.GetVName().GetCorpus(), u.Proto.GetVName().GetRoot(), u.Proto.GetVName().GetLanguage())
}

// Accumulate should be called for each unit in the kzip so its counts can be
// recorded.
func (a *Accumulator) Accumulate(u *kzip.Unit) {
Expand All @@ -80,7 +84,7 @@ func (a *Accumulator) Accumulate(u *kzip.Unit) {

cuLang := u.Proto.GetVName().GetLanguage()
if cuLang == "" {
msg := fmt.Sprintf("CU does not specify a language %v", u.Proto.GetVName())
msg := fmt.Sprintf("CU(%s) does not specify a language", cuString(u))
a.KzipInfo.CriticalKzipErrors = append(a.KzipInfo.CriticalKzipErrors, msg)
return
}
Expand All @@ -103,7 +107,7 @@ func (a *Accumulator) Accumulate(u *kzip.Unit) {
riCorpus := requiredInputCorpus(u, ri)
if riCorpus == "" {
// Trim spaces to work around the fact that log("%v", proto) is inconsistent about trailing spaces in google3 vs open-source go.
msg := strings.TrimSpace(fmt.Sprintf("unable to determine corpus for required_input %q in CU %v", ri.Info.Path, u.Proto.GetVName()))
msg := strings.TrimSpace(fmt.Sprintf("unable to determine corpus for required_input %q in CU(%s)", ri.Info.Path, cuString(u)))
a.KzipInfo.CriticalKzipErrors = append(a.KzipInfo.CriticalKzipErrors, msg)
return
}
Expand All @@ -121,7 +125,7 @@ func (a *Accumulator) Accumulate(u *kzip.Unit) {
}
srcsWithoutRI := srcs.Diff(srcsWithRI)
for path := range srcsWithoutRI {
msg := fmt.Sprintf("source %q in CU %v doesn't have a required_input entry", path, u.Proto.GetVName())
msg := fmt.Sprintf("source %q in CU(%s) doesn't have a required_input entry", path, cuString(u))
a.KzipInfo.CriticalKzipErrors = append(a.KzipInfo.CriticalKzipErrors, msg)
}
if srcCorpora.Len() != 1 {
Expand Down
2 changes: 1 addition & 1 deletion kythe/go/platform/kzip/info/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ var infoTests = []struct {
},
},
},
CriticalKzipErrors: []string{"unable to determine corpus for required_input \"file1.py\" in CU language:\"python\""},
CriticalKzipErrors: []string{`unable to determine corpus for required_input "file1.py" in CU(corpus: "" root: "" language: "python")`},
},
},

Expand Down