From b85ab0a4f1f145ff7bd5ddd8e58bf9a27148135e Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Wed, 30 Nov 2022 22:07:13 +0100 Subject: [PATCH] cmd/initContainer, cmd/run: Restore hints about unreachable code In the past, before commit d323143c468e5e59, there was either had a dummy 'return' statement or a self-documenting 'panic' that said that the code should not be reached. Since neither golangci-lint nor 'go vet' likes those, a comment is the only option left. Note that the core Go tools like 'go vet' [1], but also 'go lint' [2], explicitly don't intend to add fine-grained configuration options, including inline directives or pragmas, to silence specific warnings. That's something golangci-lint offers [3], to the extent that it's supported by its linters [4]. However, golangci-lint also uses 'go vet' as one of those linters, so it's the same problem all over again. Therefore, between the two extremes of leaving the code difficult to read and using a very big hammer to disable a needlessly big chuck of 'go vet', a comment is the least worst option. [1] https://github.com/golang/go/issues/17058 https://github.com/golang/go/issues/18432 [2] https://github.com/golang/lint/issues/263 [3] https://golangci-lint.run/usage/false-positives/ [4] https://golangci-lint.run/usage/linters/ Fallout from d323143c468e5e59dba4d209a4e4767d88dfc19e https://github.com/containers/toolbox/pull/1185 --- src/cmd/initContainer.go | 2 ++ src/cmd/run.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/cmd/initContainer.go b/src/cmd/initContainer.go index c260c2d..f52a050 100644 --- a/src/cmd/initContainer.go +++ b/src/cmd/initContainer.go @@ -361,6 +361,8 @@ func initContainer(cmd *cobra.Command, args []string) error { logrus.Warnf("Received an error from the file system watcher: %v", err) } } + + // code should not be reached } func initContainerHelp(cmd *cobra.Command, args []string) { diff --git a/src/cmd/run.go b/src/cmd/run.go index 9638233..25a8f73 100644 --- a/src/cmd/run.go +++ b/src/cmd/run.go @@ -409,6 +409,8 @@ func runCommandWithFallbacks(container string, return &exitError{exitCode, nil} } } + + // code should not be reached } func runHelp(cmd *cobra.Command, args []string) {