Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd: fix a bunch of linter warnings from GoLand #3550

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions cmd/dlv/cmds/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func New(docCall bool) *cobra.Command {
conf, loadConfErr = config.LoadConfig()
// Delay reporting errors about configuration loading delayed until after the
// server is started so that the "server listening at" message is always
// the first thing emitted. Also logflags hasn't been setup yet at this point.
// the first thing emitted. Also, logflags hasn't been set up yet at this point.
buildFlagsDefault := ""
if runtime.GOOS == "windows" {
ver, _ := goversion.Installed()
Expand Down Expand Up @@ -501,7 +501,7 @@ func dapCmd(cmd *cobra.Command, args []string) {
}

disconnectChan := make(chan struct{})
config := &service.Config{
cfg := &service.Config{
DisconnectChan: disconnectChan,
Debugger: debugger.Config{
Backend: backend,
Expand All @@ -519,7 +519,7 @@ func dapCmd(cmd *cobra.Command, args []string) {
fmt.Printf("couldn't start listener: %s\n", err)
return 1
}
config.Listener = listener
cfg.Listener = listener
} else { // with a predetermined client.
var err error
conn, err = net.Dial("tcp", dapClientAddr)
Expand All @@ -529,7 +529,7 @@ func dapCmd(cmd *cobra.Command, args []string) {
}
}

server := dap.NewServer(config)
server := dap.NewServer(cfg)
defer server.Stop()
if conn == nil {
server.Run()
Expand Down Expand Up @@ -838,7 +838,7 @@ func getPackageDir(pkg []string) string {
return listout.Dir
}

func attachCmd(cmd *cobra.Command, args []string) {
func attachCmd(_ *cobra.Command, args []string) {
var pid int
if len(args) > 0 {
var err error
Expand All @@ -852,11 +852,11 @@ func attachCmd(cmd *cobra.Command, args []string) {
os.Exit(execute(pid, args, conf, "", debugger.ExecutingOther, args, buildFlags))
}

func coreCmd(cmd *cobra.Command, args []string) {
func coreCmd(_ *cobra.Command, args []string) {
os.Exit(execute(0, []string{args[0]}, conf, args[1], debugger.ExecutingOther, args, buildFlags))
}

func connectCmd(cmd *cobra.Command, args []string) {
func connectCmd(_ *cobra.Command, args []string) {
if err := logflags.Setup(log, logOutput, logDest); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
Expand All @@ -871,7 +871,7 @@ func connectCmd(cmd *cobra.Command, args []string) {
logflags.Close()
os.Exit(1)
}
ec := connect(addr, nil, conf, debugger.ExecutingOther)
ec := connect(addr, nil, conf)
logflags.Close()
os.Exit(ec)
}
Expand Down Expand Up @@ -909,7 +909,7 @@ func splitArgs(cmd *cobra.Command, args []string) ([]string, []string) {
return args, []string{}
}

func connect(addr string, clientConn net.Conn, conf *config.Config, kind debugger.ExecuteKind) int {
func connect(addr string, clientConn net.Conn, conf *config.Config) int {
// Create and start a terminal - attach to running instance
var client *rpc2.RPCClient
if clientConn != nil {
Expand Down Expand Up @@ -1058,7 +1058,7 @@ func execute(attachPid int, processArgs []string, conf *config.Config, coreFile
}

if err := server.Run(); err != nil {
if err == api.ErrNotExecutable {
if errors.Is(err, api.ErrNotExecutable) {
switch kind {
case debugger.ExecutingGeneratedFile:
fmt.Fprintln(os.Stderr, "Can not debug non-main package")
Expand Down Expand Up @@ -1089,7 +1089,7 @@ func execute(attachPid int, processArgs []string, conf *config.Config, coreFile
return status
}

return connect(listener.Addr().String(), clientConn, conf, kind)
return connect(listener.Addr().String(), clientConn, conf)
}

func parseRedirects(redirects []string) ([3]string, error) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/dlv/cmds/helphelpers/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
)

// Prepare prepares cmd flag set for the invocation of its usage function by
// hiding flags that we want cobra to parse but we don't want to show to the
// hiding flags that we want cobra to parse, but we don't want to show to the
// user.
// We do this because not all flags associated with the root command are
// valid for all subcommands but we don't want to move them out of the root
// valid for all subcommands, but we don't want to move them out of the root
// command and into subcommands, since that would change how cobra parses
// the command line.
//
Expand Down
10 changes: 5 additions & 5 deletions cmd/dlv/dlv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ func testOutput(t *testing.T, dlvbin, output string, delveCmds []string) (stdout
if err == nil {
// Sometimes delve on Windows can't remove the built binary before
// exiting and gets an "Access is denied" error when trying.
// See: https://travis-ci.com/go-delve/delve/jobs/296325131)
// See: https://travis-ci.com/go-delve/delve/jobs/296325131.
// We have added a delay to gobuild.Remove, but to avoid any test
// flakiness, we guard against this failure here as well.
if runtime.GOOS != "windows" || !strings.Contains(err.Error(), "Access is denied") {
if runtime.GOOS != "windows" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we do want to complain for errors other than access is denied.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enclosing branch checks that err == nil.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, you are right.

t.Errorf("running %q: file %v was not deleted\nstdout is %q, stderr is %q", delveCmds, debugbin, stdout, stderr)
}
return
Expand All @@ -204,7 +204,7 @@ func testOutput(t *testing.T, dlvbin, output string, delveCmds []string) (stdout

func getDlvBin(t *testing.T) string {
// In case this was set in the environment
// from getDlvBinEBPF lets clear it here so
// from getDlvBinEBPF lets clear it here, so
// we can ensure we don't get build errors
// depending on the test ordering.
t.Setenv("CGO_LDFLAGS", ldFlags)
Expand Down Expand Up @@ -308,7 +308,7 @@ func TestRedirect(t *testing.T) {

// and detach from and kill the headless instance
client := rpc2.NewClient(listenAddr)
_ = client.Detach(true)
client.Detach(true)
cmd.Wait()
}

Expand Down Expand Up @@ -427,7 +427,7 @@ func TestExitInInit(t *testing.T) {
cmd.Dir = buildtestdir
out, err := cmd.CombinedOutput()
t.Logf("%q %v\n", string(out), err)
// dlv will exit anyway because stdin is not a tty but it will print the
// dlv will exit anyway because stdin is not a tty, but it will print the
// prompt once if the init file didn't call exit successfully.
if strings.Contains(string(out), "(dlv)") {
t.Fatal("init did not cause dlv to exit")
Expand Down
2 changes: 2 additions & 0 deletions cmd/dlv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ func main() {
if Build != "" {
version.DelveVersion.Build = Build
}

const cgoCflagsEnv = "CGO_CFLAGS"
if os.Getenv(cgoCflagsEnv) == "" {
os.Setenv(cgoCflagsEnv, "-O0 -g")
} else {
logrus.WithFields(logrus.Fields{"layer": "dlv"}).Warnln("CGO_CFLAGS already set, Cgo code could be optimized.")
}

cmds.New(false).Execute()
}