Skip to content

Commit

Permalink
Make the generated errors.toml more stable if duplicated code exist
Browse files Browse the repository at this point in the history
Signed-off-by: Lonng <[email protected]>
  • Loading branch information
lonng authored and lucklove committed Oct 30, 2020
1 parent 39fb082 commit 3aada93
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions components/errdoc/errdoc-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,21 @@ func main() {
Description string
Workaround string
}
var sorted []spec
var dedup = map[string]struct{}{}
var dedup = map[string]spec{}
for _, e := range allErrors {
terr, ok := e.(*errors.Error)
if !ok {
println("Non-normalized error:", e.Error())
} else {
val := reflect.ValueOf(terr).Elem()
codeText := val.FieldByName("codeText")
if _, found := dedup[codeText.String()]; found {
message := val.FieldByName("message")
if previous, found := dedup[codeText.String()]; found {
println("Duplicated error code:", codeText.String())
continue
if message.String() < previous.Message {
continue
}
}
dedup[codeText.String()] = struct{}{}
message := val.FieldByName("message")
description := val.FieldByName("description")
workaround := val.FieldByName("workaround ")
s := spec{
Expand All @@ -151,10 +151,14 @@ func main() {
if workaround.IsValid() {
s.Workaround = workaround.String()
}
sorted = append(sorted, s)
dedup[codeText.String()] = s
}
}
var sorted []spec
for _, item := range dedup {
sorted = append(sorted, item)
}
sort.Slice(sorted, func(i, j int) bool {
// TiDB exits duplicated code
if sorted[i].Code == sorted[j].Code {
Expand Down

0 comments on commit 3aada93

Please sign in to comment.