From 1df3a735d3b12cf2ec62f4f56ac81259e178e74f Mon Sep 17 00:00:00 2001 From: Nick Santos Date: Thu, 29 Apr 2021 14:42:18 -0400 Subject: [PATCH] go-to-protobuf: small fixes to improve debuggability - If a package isn't found, print the package name instead of segfaulting - Init klog flags, like in other code-generator/cmd packages, to turn on verbose logging --- .../src/k8s.io/code-generator/cmd/go-to-protobuf/main.go | 2 ++ .../code-generator/cmd/go-to-protobuf/protobuf/cmd.go | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/staging/src/k8s.io/code-generator/cmd/go-to-protobuf/main.go b/staging/src/k8s.io/code-generator/cmd/go-to-protobuf/main.go index 847a6a5a02b..009973389b4 100644 --- a/staging/src/k8s.io/code-generator/cmd/go-to-protobuf/main.go +++ b/staging/src/k8s.io/code-generator/cmd/go-to-protobuf/main.go @@ -23,11 +23,13 @@ import ( flag "github.com/spf13/pflag" "k8s.io/code-generator/cmd/go-to-protobuf/protobuf" + "k8s.io/klog/v2" ) var g = protobuf.New() func init() { + klog.InitFlags(nil) g.BindFlags(flag.CommandLine) goflag.Set("logtostderr", "true") flag.CommandLine.AddGoFlagSet(goflag.CommandLine) diff --git a/staging/src/k8s.io/code-generator/cmd/go-to-protobuf/protobuf/cmd.go b/staging/src/k8s.io/code-generator/cmd/go-to-protobuf/protobuf/cmd.go index de782e98f75..f7c8fb7ffca 100644 --- a/staging/src/k8s.io/code-generator/cmd/go-to-protobuf/protobuf/cmd.go +++ b/staging/src/k8s.io/code-generator/cmd/go-to-protobuf/protobuf/cmd.go @@ -364,7 +364,12 @@ func Run(g *Generator) { func deps(c *generator.Context, pkgs []*protobufPackage) map[string][]string { ret := map[string][]string{} for _, p := range pkgs { - for _, d := range c.Universe[p.PackagePath].Imports { + pkg, ok := c.Universe[p.PackagePath] + if !ok { + log.Fatalf("Unrecognized package: %s", p.PackagePath) + } + + for _, d := range pkg.Imports { ret[p.PackagePath] = append(ret[p.PackagePath], d.Path) } }