diff --git a/config.go b/config.go index 53cc288..7a58b94 100644 --- a/config.go +++ b/config.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" + "go.wit.com/lib/protobuf/bugpb" "go.wit.com/log" ) @@ -26,6 +27,19 @@ func (all *Repos) ConfigSave() error { data, err := all.Marshal() if err != nil { log.Info("gitpb proto.Marshal() failed len", len(data), err) + // often this is because strings have invalid UTF-8. This should probably be fixed in the protobuf code + if err := all.tryValidate(); err != nil { + return err + } else { + // re-attempt Marshal() here + data, err = all.Marshal() + if err == nil { + // validate & sanitize strings worked + log.Info("gitpb.ConfigSave() repos.Marshal() worked len", len(all.Repos), "repos") + configWrite("repos.pb", data) + return nil + } + } return err } log.Info("gitpb.ConfigSave() repos.Marshal() worked len", len(all.Repos), "repos") @@ -33,6 +47,20 @@ func (all *Repos) ConfigSave() error { return nil } +func (all *Repos) tryValidate() error { + + err := bugpb.ValidateProtoUTF8(all) + if err != nil { + log.Printf("Protobuf UTF-8 validation failed: %v\n", err) + } + if err := bugpb.SanitizeProtoUTF8(all); err != nil { + log.Warn("Sanitation failed:", err) + // log.Fatalf("Sanitization failed: %v", err) + return err + } + return nil +} + // load the repos.pb file. I shouldn't really matter if this // fails. the file should be autogenerated. This is used // locally just for speed