Skip to content

Commit

Permalink
fix(go): use %s to format protos in kzip validation error messages (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysachs committed May 31, 2023
1 parent 7611012 commit 7ed207b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
10 changes: 3 additions & 7 deletions kythe/go/platform/kzip/info/info.go
Expand Up @@ -69,10 +69,6 @@ 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 @@ -84,7 +80,7 @@ func (a *Accumulator) Accumulate(u *kzip.Unit) {

cuLang := u.Proto.GetVName().GetLanguage()
if cuLang == "" {
msg := fmt.Sprintf("CU(%s) does not specify a language", cuString(u))
msg := fmt.Sprintf("CU(%s) does not specify a language", u.Proto.GetVName())
a.KzipInfo.CriticalKzipErrors = append(a.KzipInfo.CriticalKzipErrors, msg)
return
}
Expand All @@ -107,7 +103,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(%s)", ri.Info.Path, cuString(u)))
msg := strings.TrimSpace(fmt.Sprintf("unable to determine corpus for required_input %q in CU(%s)", ri.Info.Path, u.Proto.GetVName()))
a.KzipInfo.CriticalKzipErrors = append(a.KzipInfo.CriticalKzipErrors, msg)
return
}
Expand All @@ -125,7 +121,7 @@ func (a *Accumulator) Accumulate(u *kzip.Unit) {
}
srcsWithoutRI := srcs.Diff(srcsWithRI)
for path := range srcsWithoutRI {
msg := fmt.Sprintf("source %q in CU(%s) doesn't have a required_input entry", path, cuString(u))
msg := fmt.Sprintf("source %q in CU(%s) doesn't have a required_input entry", path, u.Proto.GetVName())
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
Expand Up @@ -295,7 +295,7 @@ var infoTests = []struct {
},
},
},
CriticalKzipErrors: []string{`unable to determine corpus for required_input "file1.py" in CU(corpus: "" root: "" language: "python")`},
CriticalKzipErrors: []string{`unable to determine corpus for required_input "file1.py" in CU(language:"python")`},
},
},

Expand Down

0 comments on commit 7ed207b

Please sign in to comment.