Merge pull request #3964 from ash2k/ash2k/handle-errors2

Handle errors
This commit is contained in:
Kubernetes Prow Robot
2021-06-07 16:26:03 -07:00
committed by GitHub
25 changed files with 232 additions and 126 deletions

View File

@@ -17,17 +17,18 @@ func NewCommand() *cobra.Command {
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.ExactValidArgs(1),
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
switch args[0] {
case "bash":
cmd.Root().GenBashCompletion(os.Stdout)
return cmd.Root().GenBashCompletion(os.Stdout)
case "zsh":
cmd.Root().GenZshCompletion(os.Stdout)
return cmd.Root().GenZshCompletion(os.Stdout)
case "fish":
cmd.Root().GenFishCompletion(os.Stdout, true)
return cmd.Root().GenFishCompletion(os.Stdout, true)
case "powershell":
cmd.Root().GenPowerShellCompletion(os.Stdout)
return cmd.Root().GenPowerShellCompletion(os.Stdout)
}
return nil
},
}
}

View File

@@ -104,9 +104,9 @@ func (r *AnnotateRunner) ExecuteCmd(w io.Writer, pkgPath string) error {
return err
}
// print error message and continue if there are multiple packages to annotate
fmt.Fprintf(w, "%s\n", err.Error())
_, _ = fmt.Fprintf(w, "%s\n", err.Error())
} else {
fmt.Fprint(w, "added annotations in the package\n")
_, _ = fmt.Fprint(w, "added annotations in the package\n")
}
return nil
}

View File

@@ -27,7 +27,7 @@ const (
// ConvertToBuiltInPlugin converts the input plugin file to
// kustomize builtin plugin and writes it to proper directory
func ConvertToBuiltInPlugin() error {
func ConvertToBuiltInPlugin() (retErr error) {
root, err := inputFileRoot()
if err != nil {
return err
@@ -47,7 +47,12 @@ func ConvertToBuiltInPlugin() error {
if err != nil {
return err
}
defer w.close()
defer func() {
closeErr := w.Close()
if retErr == nil {
retErr = closeErr
}
}()
// This particular phrasing is required.
w.write(
@@ -139,10 +144,10 @@ func makeOutputFileName(root string) string {
"..", "..", "..", "api", packageForGeneratedCode, root+".go")
}
func (w *writer) close() {
func (w *writer) Close() error {
// Do this for debugging.
// fmt.Println("Generated " + makeOutputFileName(w.root))
w.f.Close()
return w.f.Close()
}
func (w *writer) write(line string) {